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

Thread: Can't set Teensy 3.6 serial port to 1200 baud

  1. #1
    Junior Member
    Join Date
    Jun 2021
    Location
    Melbourne, Australia
    Posts
    12

    Can't set Teensy 3.6 serial port to 1200 baud

    Hello

    I am using Teensy 3.5, Using Arduino compiler 1.8.15.

    I am simply setting up an RS232 port (Serial 2) to talk to/from a weather sensor which operates at 1200 baud.

    This (standard) code works as expected, no issues on Teensy 3.5:
    Code:
    WEATHER.begin(1200);WEATHER.setTimeout(5);WEATHER.addMemoryForRead(bufferWs,50);
    All reading and writing to and from the port works as expected.

    I was unable to get Teensy 3.5's so I started using Teensy 3.6's.

    Everything functions as expected, except that I am unable to set the baud rate on the Teensy 3.6 to 1200.
    The same code, as above, does not work.

    However, I found that the Teensy 3.6 can work if I set the baud rate to 9600:
    Code:
    WEATHER.begin(9600);WEATHER.setTimeout(5);WEATHER.addMemoryForRead(bufferWs,50);
    Does anyone know why the serial port Teensy 3.6 can't be set to 1200 baud?

    Thanks

    Gary

  2. #2
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    16,015
    May be a clock setting problem not tested to an external device at that rate?

    Can you cross Serial2 Rx/Tx to another port on the {same or other} T_3.6 and set them both up at 1200 baud and try send and receive on each?

    If they work to talk to each other, the problem is likely a clock setting issue.

    If the lines can connect to an LA/Scope the rate present could be shown perhaps to see if the error is minor or major.

  3. #3
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    10,543
    Try looking at https://www.pjrc.com/teensy/td_uart.html farther down in page shows tackle of baud rates

    it depends on which hart you are using.

  4. #4
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    16,015
    Quote Originally Posted by KurtE View Post
    Try looking at https://www.pjrc.com/teensy/td_uart.html farther down in page shows tackle of baud rates

    it depends on which hart you are using.
    Thanks Kurt - meant to get that page linked ... shows 14% error on clock math @1200 baud for T_3.6 ???

  5. #5
    Junior Member
    Join Date
    Jun 2021
    Location
    Melbourne, Australia
    Posts
    12
    Quote Originally Posted by KurtE View Post
    Try looking at https://www.pjrc.com/teensy/td_uart.html farther down in page shows tackle of baud rates

    it depends on which hart you are using.
    Thanks, Yes I've just taken a look at that chart.
    Looks like Serial 1 UART at 1200 is 14% in error on the 3.6, but ok on the 3.5, with a CPU clock at 180MHz.

    So that explains that.

    Since the UART speed seems dependent on the CPU clock I wonder if changing the CPU clock will change the error?
    I might try that.

    Gary

  6. #6
    Senior Member BriComp's Avatar
    Join Date
    Apr 2014
    Location
    Cheltenham, UK
    Posts
    756
    Could you not user Serial3, it's right next door to Serial2?

  7. #7
    Junior Member
    Join Date
    Jun 2021
    Location
    Melbourne, Australia
    Posts
    12
    Quote Originally Posted by BriComp View Post
    Could you not user Serial3, it's right next door to Serial2?
    Nope.

    This is a production PCB, designed to use the Teensy 3.5.
    Everything has been going well, but over the past few months, Teensy 3.5 has been impossible to source.
    So I started looking at the Teensy 3.6, which has got the same pinout - hence the problem.

  8. #8
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    26,398
    Quote Originally Posted by garymq View Post
    Does anyone know why the serial port Teensy 3.6 can't be set to 1200 baud?
    It's a hardware limitation. Freescale (now NXP) decided to connect the UARTs for Serial1 & Serial2 to the faster CPU clock (F_CPU). The other 4 ports run from the slower peripheral clock (F_BUS). The other Kinetis chips do this too, so you get some serial ports capable of much higher baud rates.

    A more thoughtful design would have increased the number of bits in the baud rate divider on the ports which run from a higher clock speed. But that's not the way they made the chip. All the UARTs (except the one for Serial6) have exactly the same baud rate hardware with a 13 bit divider. And of course the UART divides the clock by 16 too.

    So the slowest possible baud rate is Clock (8192 16). On Serial1 & Serial2, the clock is 180 MHz, which results in a slowest baud rate of 1373 bits/sec.

    I afraid the only way to get 1200 baud on Serial2 is to slow the CPU clock. You can do that with Tools > CPU Speed. 144 or 120 MHz should work.

  9. #9
    Senior Member BriComp's Avatar
    Join Date
    Apr 2014
    Location
    Cheltenham, UK
    Posts
    756
    Perhaps you could use this version of Software Serial. Claims to be good at slow speed and can use any two GPIO pins.

  10. #10
    Junior Member
    Join Date
    Jun 2021
    Location
    Melbourne, Australia
    Posts
    12
    Quote Originally Posted by PaulStoffregen View Post
    It's a hardware limitation. Freescale (now NXP) decided to connect the UARTs for Serial1 & Serial2 to the faster CPU clock (F_CPU). The other 4 ports run from the slower peripheral clock (F_BUS). The other Kinetis chips do this too, so you get some serial ports capable of much higher baud rates.

    I afraid the only way to get 1200 baud on Serial2 is to slow the CPU clock. You can do that with Tools > CPU Speed. 144 or 120 MHz should work.
    Paul - Thanks very much for your detailed answer!

    I tried the Teensy 3.6 compilation with CPU speed = 144MHz (instead of the default 180MHz) and Serial 2 can now be set to 1200 baud.
    As close as I can measure it was within a few percent of true 1200 speed.

    Thanks again, I can now use Teensy 3.6 in place of the 3.5..
    (Will still have to do something more drastic as both 3.6 and 3.5 are very hard to get.)

    Gary

Posting Permissions

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