Skip to content

UART Universal asynchronous receiver transmitter

MichaelMeissner edited this page Apr 15, 2020 · 13 revisions

Links

Information

  • On ARM Teensy the UARTs are 3.3V. Note, Teensy LC, 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.

  • On Teensy different 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 [ ... ]

  • There are differences across the Teensy's with regard to FIFO support. T_4.x has FIFO on all ports, T_3.x on #1 and #2. These FIFO's allow effective speeds of 2 or 3 M baud.

  • Teensy 3.1, 3.2, 3.5, 3.6, and 4.0 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 is USB Serial - using native USB hardware and does not share any pins with Serial1 like 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.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 (18), CTS3 (19);
    • Serial4: TX4 (17), RX1 (18), RTS4 (none), CTS4 (none);
    • Serial5: TX5 (20, Alt: 39), RX1 (22, Alt: 38), RTS5 (34), CTS5 (35);
    • Serial6: TX6 (24), RX6 (25), RTS6 (none), CTS6 (none);
    • Serial7: TX7 (29), RX7 (28), RTS7 (none), CTS7 (none).
  • 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 only has one serial port (Serial1) in the same location as the other Teensys. Teensy 4.0 Serial2 (pins 7/8) is in the same location as the other Teensys Serial3. The other serial ports are on different pins.

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));
	}
}
Clone this wiki locally