Teensy 4.0, Serial3, attachCts, wrong pin # in HardwareSerial3.cpp?

Status
Not open for further replies.

Silverlock

Well-known member
TL;DR version: I think cores/teensy4/HardwareSerial3.cpp has the wrong pin defined for Serial3's CTS input; it ought to be AD_B1_00 (pin 19) not AD_B1_01 (pin 18).

The details and how to reproduce it: I was trying to get RTS/CTS handshaking working with one of the hardware serial ports on the Teensy 4.0.

Digging through the HardwareSerialX.cpp files in cores/teensy4, I discovered that Serial3 brought its CTS signal out to pin 18.

I looped the Serial3 TX pin 14 back to the Serial3 TX pin 15, tied the CTS pin 18 to 3.3V via a 4.7K resistor and uploaded the following sketch and opened the serial monitor.

Code:
void setup() {
   Serial.begin(115200);
   Serial3.begin(300);
   if( !Serial3.attachCts(18) ) {
      Serial.println("Couldn't attach CTS");
   }
}

int i=0;

void loop() {
   Serial3.println(i);
   ++i;
   while( Serial3.available() ) {
      Serial.write(Serial3.read());
   }
   delay(1000);
}

Somewhat to my surprise, I saw the numbers counting slowly up. I grounded the CTS pin. No change. CTS in either state did not seem to be pausing transmission.

So I dug out a schematic of the Teensy 4.0 and saw that pin 18 was AD_B1_01, as had been indicated in the HardwareSerial3.cpp source (line 61). I opened up the i.MX RT1060 Processor Reference Manual and turned to page 473, as indicated on the following line in the source. I guess there's been an update or two to the reference manual since the code was written, because AD_B1_01 is now documented on page 489. And it showed this:

ALT2 — Select mux mode: ALT2 mux port: LPUART2_RTS_B of instance: lpuart2

RTS? That didn't look right. I was looking for CTS. Thinking this might be one of those cases where CTS and RTS were named backwards, I dug deeper into the manual. No, that's not it; RTS is definitely defined as an output and indicates that the UART is ready to receive characters, and CTS is an input and says that the UART is allowed to transmit.

I kept digging and soon discovered that AD_B1_00, on page 488, said:

ALT2 — Select mux mode: ALT2 mux port: LPUART2_CTS_B of instance: lpuart2

Ah! I looked at the schematic and discovered that AD_B1_00 came out to pin 19. I changed the pin # from 18 to 19 in HardwareSerial3.cpp and in my sketch, moved the resistor to pin 19 and tried again. Ground pin 19, transmission proceeded. Remove the ground wire and let the resistor pull the pin high, and transmission stopped.
 
Sounds good - Yep it looks like some of the tables I have were wrong. I updated my excel.

Updated code to reflect and added to my open Pull Request that added T4 support for AVR register emulation...
 
Status
Not open for further replies.
Back
Top