Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 8 of 8

Thread: Weird HWserial1 behaviour compared to Mega2560

  1. #1

    Weird HWserial1 behaviour compared to Mega2560

    I am moving a program from a Mega2560 to Teensy 3.5 and have discovered a very very strange issue to do with serial comms - specifically the behaviour when trying to make changes to the Ublox GPS chip through U-center. (I had problems writing the direct commands first, but have removed all my code completely from the situation and have replicated the problem with just this code and U-center.

    void setup()
      Serial.begin(115200);     // communication with the host computer
    void loop()
      if ( Serial1.available() )   {
        Serial.write( );
      if ( Serial.available() )       {
        Serial1.write( );
    When this code runs using hardwareserial1 on the Mega2560, it works fine and I can send commands through U-center to the GPS chip.

    When the very same code runs on the Teensy 3.5 it looks ok to start with - U-center gets a connection, reads alll the NMEA just fine, viewing the serial direct shows complete sentences etc... However I cannot successfully make any config changes to the GPS through U-center. The binary view in U-center shows the command going out, but I can't see any acknowledgements from the GPS, not even an error. I have triple checked the RX is connected and working - both continuity from the pin on the GPS to the pin on the Teensy, and serial to another arduino.

    I'm utterly stumped. It looks like the Serial on the Teensy is behaving differently enough from that of the Mega2560 to break transmit somehow _ I know that sounds stupid!

    I am using 115200 from the arduino to PC (USBserial), and have replicated the issue at 9600, 19200 and 115200 on the GPS comms on HWserial1. (changes made through the mega2560)

    Merry Xmas!!!

    Cheers - N

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    I know you're checked the wiring over and over, but that's still the most likely issue. Maybe post photos and links to the info on this module, so we can take a look and see if there's something you may be missing?

    This code really should work.

    In the things much less likely, Teensy's output is a 3.3V signal and Arduino Mega gives a 5V logic output. Maybe this Ublox GPS needs a full 5V signal on its receive pin? In the *really* unlikely differences is the much higher speed of Teensy. But this should be constrained by the serial speed at 9600 baud, on both boards. Still, maybe put some small delays in the code? (though I'd imagine that's very unlikely to be the issue)

  3. #3
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    I am guessing along the same line as Paul.

    It would help to see a picture of your setup. It might show if there are issues, like you are using a breadboard and have not soldered the pins to the Teensy. Or if maybe the wrong IO pins or that there is no ground wire running to the module.

    As he mentioned it would be good to know which unit you are talking to. My quick google, looked like several of them take power input of up to 3.6v so I am assuming that these would work fine with the 3.3v IO levels.

  4. #4
    Thanks for the replies gentlemen... I didn't get a chance to put everything in last night (it was LATE) but here are some more details and what I have tried...

    - I tried powering the GPS from VIN (while the 3.5 was powered from USB) so it gets ~5v. Same problem
    - I tried powering the GPS from the working mega2560 (3.3 and 5v) while connected to serial1 on the 3.5. Same problem.
    - I tried underclocking the 3.5 to 72 and 24Mhz - same problem both times. (I previously have had issues with an old SD logger on a Teensy 3.2 where it needed to be way underclocked to work)
    - I put a delay(5) (and tried delay(2) as well) in the 'if serial1.available' conditional although now as I look at it, of course that's the wrong conditional for RX!. I'll try adding those to the other conditional to slow down sending.

    I have found a strange mention in a forum post here:
    I found that if you use the hardware serial from arduino that you can not configure the receiver with u-center. It works with softwareSerial. If someone knows why, please let me know. :)
    That wasn't referring to a Teensy at all, but raised a red flag.

    I am a little hesitant to show the config as it's using compression pin fitting in a 3d printed base. All other connections (i2c, canbus, power, ground etc) work fine using this and the serial RX/TX are solid electrical connections according to a multimeter.

    I have a Teensy 3.2 as well I am going to see if I can replicate the issue on, and I may also be able to try configuring softwareserial as well on the 3.2 and perhaps 3.5 (It's pretty plumbed in to where it is) and see if behaviour changes.

    I have also read that serial1 and serial2 have hardware fifos which increase performance. Is there any chance that serial3 may be worth trying?

    Will report back shortly with Teensy3.2 and different delay test results.

    Neil Gardner

  5. #5
    The same GPS board works fine with a Teensy 3.2 (a counterfeit admittedly - when I discovered I had a counterfeit that's when I bought the legit 3.5s off PJRC direct). The delay(5) (or (25)) didn't make any difference in the loop on the 3.5.

    One more change. I had modified the RX buffer on the HWserial on the 3.5 (it was necessary as I am not clever enough to refactor my code to use interrupts!) up to 250. I'll drop that back to defaults and see what happens.

    Cheers -N

  6. #6
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Did the hardware serial program really work on Arduino Mega?

    If only software serial actually works, then maybe this GPS module can't really do full duplex communication? Perhaps the U-center software is actually depending on the Arduino code to store incoming messages and only send them to the GPS when it's not sending to the Arduino?

  7. #7
    The HWserial really did work on the mega. Connected to pins 18 and 19 (TX1 and RX1) and the only changes in the IDE were to change board type and serial port. Then hit "Upload". No change made to sketch.

    (as above, it also works on a counterfeit Teensy 3.2 as well). I just dropped the serial1.c file back to defaults and that made no improvement either).

    I'll pop this 3.5 out of it's prototype 3d printed base and test it with f2f connectors only (as well as try other HWserials)

    Cheers - N

  8. #8
    Sheesh. Works on serial2, not serial1. I have another 3.5 I will grab over the next day or so to verify I've busted serial1 on this one somehow. Fortunately there are enough serials on here for me to just move to another! I think on balance I am glad it's a HW issue - at least that's something I can confidently work around.

    Thanks for the suggestions and patience. Merry Xmas!

    Cheers - Neil G

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts