Can't set Teensy 3.6 serial port to 1200 baud

garymq

Member
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
 
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.
 
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
 
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.
 
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.
 
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
 
Back
Top