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.