Doubt Regarding setRX function in Teensy 4.0

tech.anurag01

New member
Hello all,
I was trying to explore how to use the setTX() and setRX() functions using teensy4.0.
from the following link: https://www.pjrc.com/teensy/td_uart.html , i got the information that I can use pins 1, 2, 3, 4, 5, 7, 8, 30, 31, 32, 33 and 0, 34, 35, 36, 37, 38, 39 as alternate RX pins for Serial1. I have written the following two programs and uploaded them on two teensy 4.0's.

1st Program uploaded on the 1st teensy:
Code:
char input;
void setup()
{
  Serial1.setRX(4);
  Serial.begin(9600);  
  Serial1.begin(9600);
}

void loop()
{
  if (Serial1.available() > 0)
  {
    input = Serial1.read();
    Serial.println(input);
  }

  if (Serial.available() > 0)
  {
    input = Serial.read();
    Serial.println(input);
  }
}

2nd Program uploaded on the second teensy:
Code:
void setup()
{
  Serial1.begin(9600);
}

void loop()
{
  delay(1000);
  Serial1.print('a');
}

I have connected pin 1 (TX for Serial1) of the second teensy to pin 4 of the first teensy. I was expecting teensy 1 to print 'a' to the terminal, but it did not happen.
When I connected the wire to pin0 (default RX for Serial1) it started printing 'a' to the console. This means that the RX pin of Serial1 has not been re-configured to pin 4.

Could someone point out the mistake that I have done in my code or point me in the right direction?

Additionally, as per the link that I shared above, the TX pins in teensy 4.0 don't have any alternate pins and hence the setTX() function is of no use in teensy4.0. Am I correct?

Thank you
 
Hi All,

A quick update regarding this.
the program works fine if the setRX() function is used after the Serial1.begin() fn.
In the following webpage: https://www.pjrc.com/teensy/td_uart.html (Accessed on 29th Jan, 2023) the following is said about the setRX() fn: "This function may be called before Serial1.begin(baud), to pre-configure the pin used." This might need to updated as it will result in the problem I mentioned in my orignal post.

Hope this helps the people facing a similar problem.

Regards
 
Back
Top