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

Thread: Teensy 3.2 odd results with Slow Baud rates and High CPU Speeds

  1. #1
    Junior Member
    Join Date
    Jul 2017
    Location
    NJ
    Posts
    6

    Teensy 3.2 odd results with Slow Baud rates and High CPU Speeds

    ***SOLVED*** Serial3 has a lower minimum Baud Rate then Serial1 & 2.

    First post here, looks like a lot of smarties in here and even developer activity so I feel in good hands.
    I've been very excited to get into Teensy becuase of the incredible specs vs an ATMEL, but as usual a few snags have come up.

    So, I've got a Teensy 3.2, bought from adafruit. Using Arduino IDE 1.8.3 and the Teensy Loader.
    Issue comes when working with low baud rates for Async Communication and using High CPU Speeds.

    My end goal is to read a Serial Stream coming from a vehicle's TCU, which has a Baud Rate of only 500, so quite slow.
    For debugging purposes I am just doing Arduino UNO Hardware UART to Teensy 3.2 Hardware UART to keep variables low.
    I can use an UNO or other atmel 328p chip at these lower baud rates fine, but the teensy seems very picky and quite random.

    I have an ebay-special Logic Analyzer which has been extremely helpful in narrowing down my problem so now lets get to the setup.


    Arduino Uno pin 1 TX goes to Teensy 3.2 pin 9 RX2, both are running at 500 baud.
    If I try to read the serial output of teensy to the IDE Serial Monitor over Serial0 then I get a repeatable pattern, but not the correct numbers.

    So now the Logic Analyzer is hooked up to UNO TX and 3.2 TX1, both output (Serial Write) the number 85 at a baud of 500.
    The UNO show an actual baud of 533 (9600 / byte length of 18.0230ms)
    The Teensy shows an actual baud of 1,680 (9600 / 5.7125ms) at 96mhz compile.

    Now here's where things get interesting, If I change the CPU speed, the baud output will change too.

    Teensy 3.2 at 120MHz = 1,175 baud
    Teensy 3.2 at 96MHz = 1,680 baud
    Teensy 3.2 at 72MHz = 5,940 baud
    Teensy 3.2 at 48MHz = 533 baud
    Teensy 3.2 at 24MHz = 533 baud

    As you can see, the lower clock speeds seem to be more accurate at the lower bauds. If I push even lower to 300 baud, Teensy is only accurate at 24MHz.

    Curious what insight people may have. I find that this is not very linear as increasing or decreasing the baud by only a few digits can change the output by quite a bit.

    Here is a screenshot of the two outputs. The top row is the Teensy 3.2 and the bottom is the Arduino Uno, both serial writing 85 at 500 baud.
    Click image for larger version. 

Name:	Screen Shot 2017-07-27 at 1.32.54 AM.jpg 
Views:	135 
Size:	69.9 KB 
ID:	11094

    Input welcome!
    Last edited by NickInTimeFilms; 07-27-2017 at 08:26 PM. Reason: Solved

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    25,491
    Teensy 3.2 can't do these slow baud rates on Serial1 and Serial2.

    The minimum baud rate is F_CPU / (16 * 8191). At 96 MHz, this means you can't get less than 732.51 baud.

    Serial3 uses F_BUS, which is half the F_CPU speed for 72 & 96 MHz, so you can get to somewhat slower baud rates on Serial3. That should work for this project where you need 500 baud.

    But for *really* slow baud rates, unfortunately the hardware has only a 13 bit baud rate divisor. It just can't get to those very slow rates when the clock is faster.

  3. #3
    Junior Member
    Join Date
    Jul 2017
    Location
    NJ
    Posts
    6
    Quote Originally Posted by PaulStoffregen View Post

    The minimum baud rate is F_CPU / (16 * 8191). At 96 MHz, this means you can't get less than 732.51 baud.

    Serial3 uses F_BUS, which is half the F_CPU speed for 72 & 96 MHz, so you can get to somewhat slower baud rates on Serial3.
    Excellent Info here! So even at 120MHz, the min baud comes out to 457.82 on Serial 3 so no issues at all there. Logic Analyzer confirms this.
    Shame I didn't discover this before I spun up some PCBs, but I suppose even 48MHz is a nice step up from 16.

    I feel like this should belong on a Teensy "Quarks" page or something to reveal oddities when coming from the Atmel world. Just a thought.

    Thanks for the fast and informative reply!

Posting Permissions

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