UART Universal asynchronous receiver transmitter - TeensyUser/doc GitHub Wiki

Links

Information

  • On ARM Teensy the UARTs are 3.3V. Note, Teensy LC, 3.0, 3.6, and 4.0 can be damaged if they are attached to a 5v system via a UART and the voltage is not converted to 3.3 volts.

  • Physical connection requires RX, TX, and GND between two similar devices. The GND pins must be connected to each other. TX on one device connects to RX on the other. Similarly, RX on one device must connect to the other TX.

  • Both devices must establish common connection parameters. This includes baud rate, parity setting, # of data bits and number of stop bits.

  • Different Teensy models have different number of Serial# ports: These are used as Serial1 or Serial2 [ ... ] denoted on the Teensy Card as TX1/RX1 or TX2/RX2 [ ... ].

  • Different Teensy models may have FIFO support on some serial lines. FIFO stands for first-in, first-out, and it is a hardware buffer that allows collecting the characters for input in hardware, even if the Teensy is blocking interrupts temporarily. Teensy 4.0 has FIFO on all ports, Teensy 3.x have FIFO on just serial lines #1 and #2. These FIFO's allow effective speeds of 2 or 3 M baud.

  • Teensy 3.0, 3.1, 3.2, 3.5, 3.6, 4.0, and 4.1 have hardware flow control using CTS and RTS on some serial ports. The Teensy LC does not have hardware support for CTS.

  • Some Teensys can use alternate pins for RX and TX for certain serial devices.

  • Features and functions are supported according to the Arduino Serial and Teensy Serial links.

  • On Teensy Serial (without a numeric suffix) is USB Serial. It uses native USB hardware and does not share any pins with Serial1 like it does on some Arduino devices.

Details

  • Teensy LC: 3 serial ports, no serial ports have FIFOs

    • Serial1: TX1 (1, Alt: 4, 5, 24), RX1 (0, Alt: 3, 21, 25), RTS1 (any), CTS1 (none);
    • Serial2: TX2 (10), RX2 (9), RTS2 (any), CTS2 (none);
    • Serial3: TX3 (8, Alt: 20), RX3 (7, Alt: 6), RTS3 (any), CTS3 (none).
  • Teensy 3.0, 3.1 & 3.2: 3 serial ports, Serial1 & Serial2 have 8 byte FIFOs

    • Serial1: TX1 (1, Alt: 5), RX1 (0, Alt: 21), RTS1 (any), CTS1 (18, 20);
    • Serial2: TX2 (10, Alt: 31), RX2 (9, Alt: 26), RTS2 (any), CTS2 (23);
    • Serial3: TX3 (8), RX3 (7), RTS3 (any), CTS3 (14).
  • Teensy 3.5 & 3.6: 6 serial ports, Serial1 & Serial2 have 8 byte FIFOs

    • Serial1: TX1 (1, Alt: 5, 26), RX1 (0, Alt: 21, 27), RTS1 (any), CTS1 (18, 20);
    • Serial2: TX2 (10), RX2 (9), RTS2 (any), CTS2 (23);
    • Serial3: TX3 (8), RX3 (7), RTS3 (any), CTS3 (14);
    • Serial4: TX4 (32), RX4 (31), RTS4 (any), CTS4 (none);
    • Serial5: TX5 (33), RX5 (34), RTS5 (any), CTS5 (none);
    • Serial6: TX6 (48), RX6 (47), RTS6 (any), CTS6 (none).
  • Teensy 4.0: 7 serial ports, all serial ports have 4 byte FIFOs

    • Serial1: TX1 (1), RX1 (0), RTS1 (none), CTS1 (none);
    • Serial2: TX2 (8), RX2 (7), RTS2 (none), CTS2 (none);
    • Serial3: TX3 (14), RX3 (15), RTS3 (any), CTS3 (19);
    • Serial4: TX4 (17), RX1 (18), RTS4 (none), CTS4 (none);
    • Serial5: TX5 (20, Alt: 39), RX1 (22, Alt: 38), RTS5 (any), CTS5 (35);
    • Serial6: TX6 (24), RX6 (25), RTS6 (none), CTS6 (none);
    • Serial7: TX7 (29), RX7 (28), RTS7 (none), CTS7 (none).
  • Teensy 4.1: 8 serial ports, all serial ports have 4 byte FIFOs

    • Serial1: TX1 (1), RX1 (0), RTS1 (none), CTS1 (none);
    • Serial2: TX2 (8), RX2 (7), RTS2 (none), CTS2 (none);
    • Serial3: TX3 (14), RX3 (15), RTS3 (any), CTS3 (19);
    • Serial4: TX4 (17), RX1 (18), RTS4 (none), CTS4 (none);
    • Serial5: TX5 (20, Alt: 47), RX1 (22, Alt: 46), RTS5 (any), CTS5 (43);
    • Serial6: TX6 (24), RX6 (25), RTS6 (none), CTS6 (none);
    • Serial7: TX7 (29), RX7 (28), RTS7 (none), CTS7 (none);
    • Serial8: TX8 (35), RX7 (34), RTS8 (any), CTS8 (50).
  • Teensy LC, 3.1, 3.2, 3.5, and 3.6 have the first 3 serial ports on the same pins (Serial1 = 0/1, Serial2 = 9/10, Serial3 = 7/8).

  • Teensy 4.0 and 4.1 only have one serial port (Serial1) in the same location as the other Teensys. Teensy 4.0/4.1 Serial2 (pins 7/8) is in the same location as the other Teensys Serial3. The other serial ports are on different pins.

  • Teensy 4, 4.1, Micromod: Baud Rates, generated with sketch up on forum thread

    • baud: 4608000 Actual: 4800000 Error: -4.17 osr=5, div=1
    • baud: 2000000 Actual: 2000000 Error: 0.00 osr=12, div=1
    • baud: 1000000 Actual: 1000000 Error: 0.00 osr=24, div=1
    • baud: 921600 Actual: 923076 Error: -0.16 osr=26, div=1
    • baud: 500000 Actual: 500000 Error: 0.00 osr=24, div=2
    • baud: 460800 Actual: 461538 Error: -0.16 osr=26, div=2
    • baud: 250000 Actual: 250000 Error: 0.00 osr=32, div=3
    • baud: 230400 Actual: 230769 Error: -0.16 osr=26, div=4
    • baud: 115200 Actual: 115384 Error: -0.16 osr=26, div=8
    • baud: 57600 Actual: 57692 Error: -0.16 osr=26, div=16
    • baud: 38400 Actual: 38400 Error: 0.00 osr=25, div=25
    • baud: 31250 Actual: 31250 Error: 0.00 osr=32, div=24
    • baud: 19200 Actual: 19200 Error: 0.00 osr=25, div=50
    • baud: 9600 Actual: 9600 Error: 0.00 osr=25, div=100
    • baud: 4800 Actual: 4800 Error: 0.00 osr=25, div=200
    • baud: 2400 Actual: 2400 Error: 0.00 osr=25, div=400
    • baud: 1200 Actual: 1200 Error: 0.00 osr=32, div=625
    • baud: 300 Actual: 300 Error: 0.00 osr=32, div=2500

Sample Teensy sketch

Sample Teensy sketch to feed UART Serial1 or Serial2 out USB Serial for use like an FTDI converter:

#define LOOP_BAUD   115200

void setup() {
	Serial.begin(115200);
	while (!Serial && millis() < 4000 );
	pinMode( LED_BUILTIN, OUTPUT );
	digitalWrite(LED_BUILTIN, 1);
	Serial.println("\n" __FILE__ " " __DATE__ " " __TIME__);
	Serial1.begin( LOOP_BAUD );
	Serial2.begin( LOOP_BAUD );
	Serial.print("\n Serial 1 or 2 USE BAUD::");
	Serial.println(LOOP_BAUD);
}

char rdBuff[1025];
void loop() {
	if ( Serial.available() ) {
		int ii;
		someBlink();
		while ( (ii = Serial.available()) ) {
			if ( ii > 1024 )ii = 1024;
			Serial.readBytes( rdBuff, ii);
			rdBuff[ii] = 0;
			Serial.write( rdBuff, ii );
		}
	}
	if ( Serial1.available() ) {
		int ii;
		someBlink();
		while ( (ii = Serial1.available()) ) {
			if ( ii > 1024 )ii = 1024;
			Serial1.readBytes( rdBuff, ii);
			rdBuff[ii] = 0;
			Serial.write( rdBuff, ii );
		}
	}
	if ( Serial2.available() ) {
		int ii;
		someBlink();
		while ( (ii = Serial2.available()) ) {
			if ( ii > 1024 )ii = 1024;
			Serial2.readBytes( rdBuff, ii);
			rdBuff[ii] = 0;
			Serial.write( rdBuff, ii );
		}
	}

}

uint32_t LastB = 0;
void someBlink() {
	if ( millis() - LastB > 100) {
		LastB = millis();
		digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
	}
}