serial ports clarification needed for Teensy 3.1

Status
Not open for further replies.

svatasoiu

Member
In the specs I see that Teensy 3.1 it is said to have 3 serial ports.
On the pins diagram I see 4 TX/RX, Tx1/RX1, TX2/RX2 and TX3/RX3.
There is a difference between TX/RX and the others 3?

Practically, I need to have a teensy communicate with another teensy-es on serial; like a chain, where one teensy receive a command on one serial port (RX/TX), and send the command through another serial (RX1/TX1) port to the next teensy in the chain (next teensy is receiving it on TX\RX port).
So far I used a serial command library (#include <SerialCommand.h>) that works well when I send commands from the IDE serial monitor.
From the first teensy I use Serial1.println(sCmdToNextUnit); to send the command to the next teensy.
The commands are simple text for now, like "RedLedOn", "RedLedOff" ...

The issue is that the second teensy does not receive on "Serial" port (TX/RX) the command send from the first teensy from Serial1 port (TX1/RX1).

This should be possible, but in my case it does not work and I'm not sure what the issue is.
 
The "pínk" TX/RX on pins 3 and 4 belong to the CAN bus (see lower right corner) and are NOT used for "normal" serial I/O through the UART. The TX1/RX1 with grey letters (pins 5 and 21) are alternate pins that you can use if the primary pins for TX1/RX1 (pins 0 and 1) are used for other purposes.
 
Thank you for the replay.
On my failed try I had the following connections:
Teensy #1: connected through USB to computer (Arduino serial monitor) and it was receiving serial commands through Serial.Read()

PC Teensy #1 Teensy #1 Teensy #2
USB --->?? (usb) TX1 (pin 0) -----> RX (pin 4)
--->?? RX1 (pin 1) -----> TX (pin 3)

From your answer I understand that this is incorrect.
What I thought it was that Serial.read() (I think it is Serial0 ???) it was using TX/RX inputs (pins 3/4)

What combinations of pins would work?

Teensy #1 Teensy #2
TX1 (pin 0) -----> RX2 (pin 9)
RX1 (pin 1) -----> TX2 (pin 10)

If this would work, where can I receive the input from the USB from the Arduino Serial Monitor (I want to use that input to simulate the input from a previous Teensy in the chain connection) ?
 
Yes, these pins should work. On the second Teensy, you could use pins 0 and 1 (TX1/RX1) as well.

In order to transmit and receive data on these pins, you must use the "Serial[x]" objects, as described here: https://www.pjrc.com/teensy/td_uart.html. Serial1 is for TX1/RX1, Serial2 handles TX2/RX2 and Serial3 is for - guess what - TX3 and RX3.

You can (and should) directly connect TX1 of Teensy 1 to RX1 (or RX2 or RX3) of Teensy2. There's no need for the Max232 chip shown on the linked page. That chip transforms Teensy`s 3.3 Volt signal into a higher voltage (+/- 12 V). You only would need it for longer distances or if you wanted to talk to RS232 compatible devices that work with +/- 12 volts on the data lines. However, IF you decide to use it, you MUST have one Max232 for each Teensy. DON'T feed the RS232-signals with +/-12V directly into your Teensy, unless you want to kill it on purpose...
 
Don't forget the common GND connection between the Teensy's. If both are connected to USB, there's a sneaky common ground.
 
Hello,

How do I use the alternate pins for TX1 and RX1? Posting code changes would be greatly appreciated! Or a link to the place that might indicate how to do this on the PJRC website. I looked and googled, but didn't come up with anything.

Thank you!
Tom
 
After Serial1.begin(), pins 0 and 1 will be in use.

This should disable those pins:

Code:
  CORE_PIN0_CONFIG = 0;
  CORE_PIN1_CONFIG = 0;

Then to activate the alternate pins, try this:

Code:
  CORE_PIN21_CONFIG = PORT_PCR_PE | PORT_PCR_PS | PORT_PCR_PFE | PORT_PCR_MUX(3);
  CORE_PIN5_CONFIG = PORT_PCR_DSE | PORT_PCR_SRE | PORT_PCR_MUX(3);
 
Paul,

Thanks for the speedy reply.
One questions:
Do I do this:
Serial1.begin();
CORE_PIN0_CONFIG = 0;
CORE_PIN1_CONFIG = 0;
CORE_PIN21_CONFIG = PORT_PCR_PE | PORT_PCR_PS | PORT_PCR_PFE | PORT_PCR_MUX(3);
CORE_PIN5_CONFIG = PORT_PCR_DSE | PORT_PCR_SRE | PORT_PCR_MUX(3);

Or should the Serial1.begin() be after the configuration is done. I'm guessing after, but would be good to know.



Thank you so much for the speedy response again.
 
Last edited:
Status
Not open for further replies.
Back
Top