Hello,
Recently I came into contact with EtherCat, and it made me think of something.
I want to make something similar for arduino using max485 modules (they cost 50 cents nowadays). The idea is that the Tx of the master arduino goes to the Rx of the next arduino via rs485 and this goes on and on (daisy chaining in a circle). I want to use an 8 pole flat-cable with clickable connectors (because is cheap) 2 lines are for RS 485 buses, 2 for ground and 2 for 5V lines.
I first want to start out by letting the slave arduino's act purely as IO extenders which are controlled by the master. The master sends 1 byte to initiate transmission. The ammount of bytes the master will send in a single transmission is related to the ammount of slaves. This first byte will have the value 0. Further there are 2 bytes reserved per arduino with information for and from the GPIO pins.
When the first slave reads in the 0, it knows that the following 2 bytes (bytes 1 and 2) are reserved for that particular slave. The slave will increment this 0 to 1 and immediately relays it to the next arduino. The next arduino which gets the '1' knows that bytes 3 and 4 are reserved for him. Than this arduino increments the 1 to 2 and relays it to the 3rd arduino etc etc. Finally the last arduino receives his number, increments it, and relays it to the next.
However there is no next device. Instead: The outgoing connector of the last slave will be wired so that the first rs485 is wired to the 2nd rs485 bus which will lead all the way back to the master's Rx pin. The master than receives the first byte of a packet which he is still transmitting at that moment. The received number must match with the configured ammount of slaves. If the number differs, the master knows that atleast 1 slave is malfunctioning or missing.
Received bytes are to be read and/or modified and retransmitted to the next device ASAP. Every slave has the ability to modify the received bytes before retransmitting them. The arduino can put information of it's inputs in the byte and then relays the byte to the following device untill the modified byte reaches the master.
The bytes can also already contain information regarding the output pins. The very first transmission will also initialize all IO of all slave modules. Therefor any slave's ID is depended off his position in the bus.
Summarized:
In the beginning of a transmission, a slave will receive a number, this number tells him which of the following bytes of the transmission are ment for him. These bytes may contain information for his output pins and he must OR the bits with the states of his inputs. The transmission will be fed into a 2nd rs485 bus back to the master.
The reason why I want to this, is because I use rs485 alot for my model track but I have no implemented methods for collision avoiding or collision detection. My theory was that the chances for this to happen were so incredibly small, it would not occur. This theory still stands today. Ofcourse I would like something betters. And letting the master device poll information per slave (like is done with modbus) does not have me preference.
Now the questions.
I'd like to have this running as fast as possible. I've read that the maximum baudrate of 2M for an atmega328P can be realized. However every device needs to be able to receive and transmit simultaneously. So I believe this might influence the performance too negatively?
What would the highest achiefable baudrate transceive full duplex?
Also. I've not yet looked into the hardware serial library of arduino. I've heared that not everybody thinks it is very efficient. For work I programmed an 8051 chip and a made 2 circular buffers for serial communication. So I did not had to wait while(transmitt_flag || receive_flag) all the time. Does the arduino library wait while for the transmit and receive flags or is it efficient enough?
Lastly?
Out of curiosity what do you think of my method for communicating between arduinos?
general schematic:
