One Teensy 4.1 to send/receive information to six Teensy 4.1s

Status
Not open for further replies.

Trensicourt

Active member
My goal is to have one Teensy 4.1 send and receive information from each of the seven other Teensy 4.1. How would I go about this? I've been research on using I2C by using multiple Arduinos as an example, but I can also take advantage of Teensy 4.1's 8 serial ports. Thus, I was thinking I could multiple serial#.read/write(). However, I'm not sure how feasible that is. Is there a guide I can follow to accomplish my goal?
 
It depend what your requirements are

If you need all teensy to be able to communicate at the same time then the 8 port serial is to prefer, the downside is the many required pins of the "master" teensy.

I2C is a better approach if you for example want to expand it in the future.

There is also the CAN interface.

If you want you can use RS-422/RS-458 together with the UART (serial port)
that approach is good when you have long distances between the diffferent teensy.
 
I need all teensys to communicate at the same time. I don't plan on expanding it in the future.

I don't think I need a CAN interface.

The length of wire between each Teensy is at most three meters.

Therefore, I want to use the 8 serial ports or use the RS-422/RS-458. I'm not sure which is better. I have minimal experience with using serial ports and none with RS-422/RS-458.
 
You use RS-422/RS-458 together with the serial ports,

there is also RS-232 but that often require external capacitors to work and it's also slower and support shorter cables.

At three meters I believe it's safest to use any kind of the above standards,


taken from wiki:
RS-422/RS-458 is twisted pair wire and support 1200 meters of wire
RS-232 is single wire but with +- voltage levels

RS-422 is full duplex
RS-458 is half duplex but can be full duplex using two transceivers

so with full duplex RS-422/RS-458 you will need four wires + GND for each teensy that you connect, note that the wires need to be twisted pair, for example you can use the wires from a old ethernet cable, I have recently done that with around 10 meters of cable where two pairs are used for GND and power, one pair is unused and the last pair is for half duplex data.

I have used MAX487 which is a half duplex transceiver

in your case you could use MAX488 which is a full duplex RS-422/RS-458 transceiver available in a 8pin PDIP
 
I'm looking into RS-458 and MAX488. I have only found an Arduino-based tutorial below.

https://create.arduino.cc/projecthub/moreirarobotics/how-to-communicate-3-or-32-arduinos-via-rs-485-36888f

https://www.amazon.com/Max485-Chip-RS-485-Module-Raspberry/dp/B00NIOLNAG/ref=sr_1_3?keywords=Max485+Chip+RS-485&qid=1636856895&s=industrial&sr=1-3

What would be the equivalent code and wiring, at least for an example using three Teensy 4.1 with one master and two slaves, but using Full Duplex communication.
 
The downside with that example is that it uses a master <-> slave configuration half duplex
(Which is normal? for rs-422/rs-458 networks)

And it's always the master that initiates a data request, and each slave have a unique adress.

The master can have the adress 0x00.

In simple terms it works this way:
1. All slaves are in receive mode
2. The master gets into transmit mode and then sends a message: "slave address >0" + "data request CMD" + \n (line feed)
3. The master gets into receive mode
4. The slave that matches the adress parses the data, then gets into transmit mode to send a response to the master, this response should use the adress 0x00 (so that only the master "gets" the data.


Another simpler option using max3232 (full duplex modules) could be used,
Then you can use the serial ports just like if you did connect them directly between the teensy:s.
You will then need 12 of those modules to connect 6 teensy:s to the "master".
In that case you can send commands to all teensy:s at the same time or if you have it the other way and the 6 teensy can simultaneously send data to the "master".

while at amazon i found these
https://www.amazon.com/HiLetgo-Level-Converter-Board-Rs232/dp/B00LUDCAXQ
Which is rs-232 boards
They should also work in your case
And they offer full duplex out of the box
With the capacitors already mounted.
And are cheaper.

Sorry if I confuse you with all the different options.

Btw. If you use the bare max3232 ic +caps then you have access to two senders and two receivers in one ic, which means in your application you only need 3 max3232 ic:s at the "master" side and one max3232 at each "slave"
Totally 9 max3232 ic:s.
 
I'm interested in using max3485 full duplex mode. Should I buy the module like https://www.amazon.com/Max485-Chip-RS-485-Module-Raspberry/dp/B00NIOLNAG/ref=sr_1_3?keywords=Max485+Chip+RS-485&qid=1636856895&s=industrial&sr=1-3 or just the independent IC? I'm not sure if there is a functional difference but would it easier to use a max3485 module: https://www.amazon.com/DollaTek-Development-Converter-Accessories-Replacement/dp/B08HQMDKGR? From what I've research 3485 modules are substantially more expensive per piece though I would be still willing to buy 7 of them.
 
Ok,
the first amazon link is the 5v half duplex variant
the second is by the looks of the ic on the board a MAX13487 which is still a half duplex 5V variant,
I would not trust that one.


but on mouser.com there is this one
https://www.mouser.se/ProductDetail/Maxim-Integrated/MAX3490CPA+?qs=LHmEVA8xxfb3IyJvmhZfXA==
which is the full duplex 10Mbps 3v3 variant.
it cost $4.66 at >10
so that will be $55.92 @ 12pcs

you will also need 12 "termination" resistors
https://www.mouser.se/ProductDetail...=sGAEpiMZZMtlubZbdhIBIK9P4/dtlsbdEkkWQXsAvxs=

then you can do it like this:
RS488_multiple.jpg



But if I understand, you want to do it master/slave with only 7 MAX3490 (10Mbps variant):s
then you will need the MAX3491:s at the slave teensy:s which have transmit enable (a collision will otherwise occur when two or more transmitters is activated)
RS488_multiple_variant.jpg
I this mode the master can send some data to all slaves simultaneous, but only one slave can send data back at any given time.

So if you compare it with the half duplex mode it's the same,
as all slaves are always listening for commands from the master
and if the master in half duplex mode want to send something to all slaves
it can do so by a special message.


The conclusion:
it's either the full duplex 12x MAX3490 "master"/"slave" variant or the 7x MAX3485 half duplex master/slave variant


edit.
don't forget the decoupling caps at each transceiver ic they are not in the schematic (because it takes too much time adding them)

edit.
also don't trust the datasheet at mouser as it contains errors
here is the newest one from Maxim
https://datasheets.maximintegrated.com/en/ds/MAX3483-MAX3491.pdf
 
at least with CAN you have a star network, where they all talk to each other at same time, even if one or more go offline, and you can definately go way beyond 3 meters easily
 
I have 6 slave teensy 4.1 and one master teensy 4.1. Each slave needs to be able to receive commands from the master and be able to send information to the master if requested. However, each slave needs to be able to send information to the master when there is an issue without the master requesting it. This means I need to prevent collisions if multiple slaves detect issues. From how I understand each proposal so far, I will need each teensy to communicate equivalently and not as a master/slave configuration. I could be wrong so correct me here, I need a full-duplex RS485 configuration with what @manicksan suggested or a CAN network as both mentioned before. Which would be more appropriate for my application?

For context, the only other pins for now that I would need are SCL, SCL1, SDA, SDA1, and 1 digital pin. Therefore, using multiple pins should not be an issue. However, it is best if I don't need that many pins. Furthermore, I have limited experience with Serial Ports and I2C protocols. None with RS-based or CAN based ones and would need help with those if implemented.
 
3 wires (CANH,CANL,GND) from each teensy transceiver

Vehicles use this network because of it's reliability and guarenteed data transmission accross the network, especially in noisy environments. Should one node fail, all your nodes will know (if they have keep alive messages or data setup of your choice). You can use regular UTP cable between the teensies.

Each frame is capable of sending 8 bytes payloads at a time in CAN2.0 mode, but if you were to use CANFD, you could send up to 64 bytes payload in a single transmission

So while you can handle the 8/64 data easily as an array, if you use SPI/I2C/UART etc you will need to manage the data one byte at a time or use a library that handles the reassembly for you
 
Another solution might be to use some Ebyte E32 Lora radios.
They communicate with the Teensy using Serial Uart.
The radios can be addressed from a master broadcasting to all or individual slaves. The slaves can reply in a similar manner.
I am using a number of them in a building energy management system. One master and many slaves.
Seems to work quite well.
Details here.
You have to be prepared to have some lost packets. I have experienced when I have stood right in front of the transmitter and blocked the signal.
I have found that this can be cured quite easily with some simple handshaking.
Slave sends a message and Master replies to the Slave effectively saying thanks for your message. I include a checksum in the handshake reply to overcome any corruption but have not found any yet.
A good Teensy library already exists here.
Here is a YouTube video from the Author of the Library.
 
@BriComp
I am not going to be using wireless, since there might be electrical interference with the equipment I am using. I should've clarified.

@toton81
What modules or example wiring of a Teensy 4.1 can be used with a CAN network? For instance, I find the MAX3490 by @manicksan to be helpful if I were to implement it in a RS485 method.

Speaking of RS485, @manicksan does the MAX3490 module support full duplex two way communication? I also want to clarify for full duplex, would there be conflict in communication if a Teensy 1 receives information from multiple Teensies while also sending? Otherwise, I'm assuming that I have to switch the Teensy from receiving to sending with a small delay in between unless this is the standard for all code.
 
@manicksan

For the max3490 diagram I just want to confirm that it is indeed the max3490 and not the max3488 as it described per each IC. I am assuming each decoupling capacitor is used to reduce the noise generated from the transfer of data. These decoupling capacitors you mentioned are placed in parallel with the IC chip from VCC to ground, where the VCC is coming from the 3.3 V of the Teensy 4.1, right? Do the GND and VCC for all Teensy 4.1 and max3490 module have the to be the same? Also what is the purpose of the resistors between the twisted wires and where do I place these resistors? I am assuming from the diagram that these are placed right before the twisted wires separate to go into the inputs.

Lastly, is there a library and an example code I could use with the max3490?

For the CAN transceiver, I am reading that the Teensy 4.1 already has a CAN controller, meaning that I only need to buy the CAN transceivers you linked. Can you confirm these connections?
For each Teensy 4.1: CTX1 connects to CRX, CRX1 connects to CTX.
For each module to make sure all Teensys can communicate with each other: All CANL connects to the same node. All CANH connects to the same node.

Also, does the FlexCAN_T4 library work with Teensy 4.1?
 
yes to everything except CRX/CTX... For CAN it's TX to TX and RX to RX, same for all, all in parallel
Also CANH to CANH, CANL to CANL, all parallel

Best part is if you use CANFD to transfer large 64 byte array payloads (or CAN2.0 to handle small 8 byte payloads), you don't need to add your own CRC stuff with CAN data, the data is guarenteed to be correct/intact once received

software CRC is only needed if you want to assemble 2 of more payloads together and make sure it's valid. You could also use isotp plugin that is part of the FlexCAN_T4 to send larger payloads over CAN2.0 (8 bytes). It does all the reassembly and gives you the full payload in the callback, even if it is 100 bytes or more so long as the buffer is set to support the highest payload you'll receive over isotp

My current project uses a CAN2.0 frame request to another node to send back a payload as isotp format. once the data is reassembled the callback is fired and your data is available.
The payload size is around 112 bytes, where isotp reassembles all the 8 byte frames to rebuild and supply your payload array

Also, CAN is broadcasted, so all your teensies see the same data, obviously you tell a specific teensy what ID to work with. Each teensy could have it's own CANID, so while they can see all traffic, you decide how you want them to react :)
 
Last edited:
CAN looks very nice indeed as every teensy can talk to one and another. I guess that if the Line is busy and one teensy want to send data that is taken care of by the CAN hardware/software?
And the data is automatically sent when the line go free again.

In my big schematic they should be max3490 instead of the max3488 mentioned.

MAX3490 MAX3488 don't need any special examples except the standard serial port ones,
as the configuration is a "point to point" network.
 
The downside with CAN is that it needs a special controller, so if one (Including myself) need to connect to a small easy to solder MCU 8pin there is not so many options.
I'm using the RS-422/RS-485 together with a PIC micro that measures airline pressure for a deep well.
 
yes it is done in hardware, priority is lower CANIDs but in any case you wouldn't notice them taking turns it happens too fast for a human to perceive it. In a car for example, my bus has about 60 IDs all streaming at same time, you can print the traffic to serial monitor but you will see it scrolling non stop with all the traffic from multiple modules :)

In essense, hardware takes care of the transmits, you only need to handle the receptions
 
@manicksan
Is the SN65HVD230 CAN Bus Transceiver compliant with 3.3V? edit: I just checked, it can.

@tonton81
Do you have an example code for Teensy 4.1 to Teensy 4.1 communication with the FlexCan_T4 library?
 
The FIFO with interrupt example has send and receive capability. The code is very minimal and it can send and receive 8 bytes payload from all teensies attached
 
What's the difference between SN65HVD230 CAN Bus Transceiver and PIC18F26Q84-I/SP? Is this a controller that I attached between the Teensy 4.1 and the SN65HVD230 CAN Bus Transceiver to enable CAN FD?
 
Status
Not open for further replies.
Back
Top