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

Thread: Teensy 3.6 are all UART ports the same?

  1. #1

    Teensy 3.6 are all UART ports the same?

    Hi all, I been messing with a Nextion Display, it communicates over Serial, i programmed the display to send some byte arrays based on touch and it worked great when i tested it using Serial1 and Serial3, however then i moved it to Serial6 and it stopped working, i thought maybe i crossed TX/RX but that wasn't the case (the display does power up and all that by the way).

    The issue turned out to be that when i would call NEXTION.available() it if NEXTION is Serial1 or Serial3 it seems to return the total number of bytes, however if i use Serial6 it will then always return 1 for each of the bytes, I think i had read before that the Hardware serial ports on the 3.6 have a FIFO but maybe i'm mistaken, i figured maybe only some of the UARTs have a FIFO while the others don't.

    I can solve this issue with code but I figured I could ask if there are differences in hardware between all the UART ports here to avoid this issue again.

    If anybody can share any info on this I would appreciate it!

  2. #2
    Senior Member+ MichaelMeissner's Avatar
    Join Date
    Nov 2012
    Location
    Ayer Massachussetts
    Posts
    3,544
    On the Teensy 3.2, 3.5, and 3.6, only the first two serial ports have an 8 byte FIFO (first in, first out) hardware buffer to hold the characters received while interrupts are disabled. I believe the other serial ports do not have a FIFO buffer.

    The Teensy LC does not have any FIFIO buffers.

    The Teensy 4.0 has 8 byte FIFO for each of the serial devices.

    Note, on the Teensy 3.5/3.6, Serial4 does not support a CTS (clear to send) pin, but the other serial ports do support a CTS pin (that is a specific pin). For more information consult (unfortunately no Teensy 4.0 documentation yet):

  3. #3
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    6,579
    At the very least, all ports should work...
    I've never tried Serial6 - but this is the first time I'm reading about it not working. So it could well be a BUG... or not
    Can you do more tests?

  4. #4
    awesome, thank you for the info, i think i was testing on Serial1 and Serial2, i fixed my issue using a little buffer

  5. #5
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    6,366
    Let me know if you find one that does not work. Also let me know if you are having an issue with input or output.

    Kurt

    I know I tested them all earlier on in T4 beta. But it is always possible that maybe a table got messed up.

    On T4 all of the Serial ports run using the same code, but they simply have a hardware table that is fed into their constructor....

  6. #6
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    6,366
    I did a quick test of Serial6 and it appears like it works.

    Code:
    #define HWSERIAL Serial6
    void setup(){
      pinMode(13, OUTPUT);
      while (!Serial && millis() < 5000) ;
      Serial.begin(115200);
      HWSERIAL.begin(115200);
    }
    int loop_counter = 0;
    void loop(){
      digitalWrite(13, !digitalRead(13));
      loop_counter++;
      HWSERIAL.printf("Loop Count: %d\n", loop_counter);
      delay(100);
      while (HWSERIAL.available()) {
        Serial.write(HWSERIAL.read());
      }
    }
    I first did it without the reading from the port, just doing the output and hooked up to logic Analyzer and it showed proper output at 115200 baud rate...
    Then tried with the above program with pins 24 jumperred to 25 and I am getting loop count line being output in serial terminal.

  7. #7
    Quote Originally Posted by KurtE View Post
    I did a quick test of Serial6 and it appears like it works.

    Code:
    #define HWSERIAL Serial6
    void setup(){
      pinMode(13, OUTPUT);
      while (!Serial && millis() < 5000) ;
      Serial.begin(115200);
      HWSERIAL.begin(115200);
    }
    int loop_counter = 0;
    void loop(){
      digitalWrite(13, !digitalRead(13));
      loop_counter++;
      HWSERIAL.printf("Loop Count: %d\n", loop_counter);
      delay(100);
      while (HWSERIAL.available()) {
        Serial.write(HWSERIAL.read());
      }
    }
    I first did it without the reading from the port, just doing the output and hooked up to logic Analyzer and it showed proper output at 115200 baud rate...
    Then tried with the above program with pins 24 jumperred to 25 and I am getting loop count line being output in serial terminal.
    Ok I tested your code i jumpered Serial6 RX/TX (pins 47/48) and Serial6.available does show up the full length of the array, however when i go back to the nextion display .available() will still always return 1, i'm guessing it has to do with the display.

    Additionally i set it to use serialEvent6() and .available still returns 1, I'll do some more research on the Nextion display but I think for now i know it's not Serial6 causing any issues

    Thank you for your help!

  8. #8
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    6,366
    Oops I was thinking Teensy 4... And you have T3.6...

    On T3.6 Serial6 is a complete other animal. It does not internally use a UART hardware instead it uses an LPUART hardware... Which have different registers and the like.

    It has been a long time since I played with this code. I will try to take a look soon.

  9. #9
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    6,366
    Quick update: pulled out a T3.6 (actually 2nd one) as the first one I pulled out has a problem with the two IO pins associated with Serial6...

    And test program I posted worked fine.

    Note: I modified it slightly:
    Code:
    #define HWSERIAL Serial6
    void setup() {
      pinMode(13, OUTPUT);
      while (!Serial && millis() < 5000) ;
      Serial.begin(115200);
      HWSERIAL.begin(115200);
    }
    int loop_counter = 0;
    void loop() {
      digitalWrite(13, !digitalRead(13));
      loop_counter++;
      HWSERIAL.printf("Loop Count: %d\n", loop_counter);
      delay(100);
      if (HWSERIAL.available()) {
        Serial.printf("(%d)- ",HWSERIAL.available()); 
        while (HWSERIAL.available()) {
          Serial.write(HWSERIAL.read());
        }
      }
    }
    To see if Serial.available would return a value > 1 as we waited for 100ms which should allow enough time for stuff to come in...


    Code:
    (14)- Loop Count: 1
    (14)- Loop Count: 2
    (14)- Loop Count: 3
    (14)- Loop Count: 4
    (14)- Loop Count: 5
    (14)- Loop Count: 6
    (14)- Loop Count: 7
    (14)- Loop Count: 8
    (14)- Loop Count: 9
    (15)- Loop Count: 10
    (15)- Loop Count: 11
    (15)- Loop Count: 12
    (15)- Loop Count: 13
    (15)- Loop Count: 14
    (15)- Loop Count: 15
    Now if I modify it to user the SerialEvent6 function, like:
    Code:
    #define HWSERIAL Serial6
    elapsedMillis elapsed_since_last_char;
    int count_serialEvent6_calls = 0;
    void setup() {
      pinMode(13, OUTPUT);
      while (!Serial && millis() < 5000) ;
      Serial.begin(115200);
      HWSERIAL.begin(115200);
      elapsed_since_last_char = 0;
    
    
    }
    int loop_counter = 0;
    void loop() {
      if (elapsed_since_last_char > 250) {
        Serial.printf("(%d):", count_serialEvent6_calls);
        elapsed_since_last_char = 0;
        count_serialEvent6_calls = 0;
        digitalWrite(13, !digitalRead(13));
        loop_counter++;
        HWSERIAL.printf("Loop Count: %d\n", loop_counter);
      }
    }
    void serialEvent6() {
      elapsed_since_last_char = 0;
      count_serialEvent6_calls++;
      while (HWSERIAL.available()) {
        Serial.write(HWSERIAL.read());
      }
    }
    As expected I got one character per each time I called SerialEvent6...
    Code:
    0):Loop Count: 1
    (14):Loop Count: 2
    (14):Loop Count: 3
    (14):Loop Count: 4
    (14):Loop Count: 5
    (14):Loop Count: 6
    (14):Loop Count: 7
    (14):Loop Count: 8
    (14):Loop Count: 9
    (14):Loop Count: 10
    (15):Loop Count: 11
    (15):Loop Count: 12
    But if I have the main loop busy without calling something the yields (example delay(1)) will yield. Maybe something like:
    Code:
    void loop() {
      if (elapsed_since_last_char > 250) {
        Serial.printf("(%d):", count_serialEvent6_calls);
        elapsed_since_last_char = 0;
        count_serialEvent6_calls = 0;
        digitalWrite(13, !digitalRead(13));
        loop_counter++;
        HWSERIAL.printf("Loop Count: %d\n", loop_counter);
      } else {
        elapsedMicros delay_loop = 0;
        while (delay_loop < 250) ;
    //    delay(5);
      }
    }
    You now see that the times the serialEvent6 decreases (i.e. it may process more than one character)
    Code:
    (0):Loop Count: 1
    (5):Loop Count: 2
    (5):Loop Count: 3
    (5):Loop Count: 4
    (5):Loop Count: 5
    (5):Loop Count: 6
    (5):Loop Count: 7
    (5):Loop Count: 8
    (5):Loop Count: 9
    (5):Loop Count: 10
    (6):Loop Count: 11
    (6):Loop Count: 12
    (6):Loop Count: 13
    (6):Loop Count: 14
    (6):Loop Count: 15
    So far everything is working as I would expect. So may need more specific information on your setup and code. Which display do you have?

  10. #10
    KurtE if i do a test similar it will also work and .available() will return more than 1, however when its with the nextion display it always returns 1, i have enhaced nextion 3.2 touch display.

    I should have also mentioned Iím using Serial 1 and Serial 3 for dual MIDI IO in my code as well.

    Tomorrow iíll be able to test it further and test it on all Serial ports and see if theres any difference.

Posting Permissions

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