T4 No SPI Slave, No I2C Slave. how to make multiple Teensys talk with more hardware

Status
Not open for further replies.

alrj

Well-known member
As per the topic. I need to get a few of these talking to each other! There is no slave options in any of the libs it seems...

I have tried RichardG's valiant effort at adding I2C slave to the teensy but it wont compile when I add the Audio and LCD libs.. https://forum.pjrc.com/threads/57861-I2C-Slave-on-Teensy-4

What solutions are other people using? Many thanks, Al.

edit: the topic is meant to say "without more hardware" but I cant change it.
 
Your other options would be USB or UART, USB is the fastest but of course you need a hub if you want to connect more than one Teensy to another.
 
Thanks vjmuzik, I wasn't aware you could easily talk to multiple devices using uart, I will have more of a look into that. Is there a suitable library known working for T4?

edit: it doesn't seem like there is a solid/easy way to talk to multiple devices using UART unless I am missing something.
 
For Teensy 4.0 you have 7 UARTs available, 8 for 4.1, if you don’t want to get the hardware for rs485 that would be the max number of devices you could easily connect together without daisy chaining.
 
Thanks I will look into rs485, I want to send a signal from the master to several slaves all at the same time, as well as communicate with each individually. Maybe my time is better spent looking into the raw implementation of I2C that RichG has done.
 
Thanks I will look into rs485, I want to send a signal from the master to several slaves all at the same time, as well as communicate with each individually. Maybe my time is better spent looking into the raw implementation of I2C that RichG has done.

You don't need the master to have a separate uart to talk to each slave. Just have a protocol where the first byte/half-word/word or so of the message says which slaves to talk to. The slaves will ignore any message that isn't addressed to them or is listed as a broadcast message. In principal, this is how I2C, ethernet, etc. work where all devices see the traffic, but they are only looking for specific messages.

To make things simpler, you would probably want to have a protocol where the slave only sends data when the master queries it to prevent multiple slaves talking at the same time. That way you don't have to worry about messages posted at the same time from different slaves.

Alternatively, you could have a common communication channel (i.e. uart/can), and have a separate pin to indicate that the master is talking to a specific slave. In essence, this is what SPI does with the CS pins.

Note, for serial, you may to adjust the serial speeds if you send a lot of data, or use hardware flow control. Unfortunately on the Teensy 4.0/4.1, the 3 uarts that support using CTS (clear to send) for hardware flow control have issues:
  • Serial3 (pins 14/15) uses pin 19 for CTS. Unfortunately pin 19 is used for the main I2C bus;
  • Serial5 (pins 20/21) uses pin 34 (Teensy 4.0) or 42 (Teensy 4.1) for CTS. Unfortunately this pin is only available in the pins for the SD reader;
  • Serial8 on the Teensy 4.1 (pins 34/35) uses pin 50 for CTS. Unfortunately this pin is only available in the pads underneath the Teensy for soldering flash and psram memories.

If you can keep the message fixed size, and 4 bytes, it should fit directly in the FIFO, and reduce problems with missing data due to interrupts at higher speeds.
 
Thanks Michael, after lots of tinkering I have realised I don't need 2 way communication, so I have the master with TX connected to the RX of a slave, next I was thinking of just adding another wire from the same TX to another slave. the data from the master can always go to all slaves now that I have made some tweaks to the code. A
 
Status
Not open for further replies.
Back
Top