Hello, thanks for your reply.
As for my project, I need to talk with up to 16 arduino’s over a distance of 500m using a field bus in real fields (cow shit included
). For this RS485 seemed most appropriate. However, the CAN bus might have done as well I guess (Electrically speaking the two busses are not so different: RS485 drives the voltage in two directions, CAN transceivers in only one).
As price is concerned this does not seem to be an issue (and RS485 transceivers are slightly cheaper). I designed my own printed circuit board with an Atmega328/Arduino and all the electronics I need for my application. Adding an RS485 transceivers was of the order of 1 €.
For bus occupancy detection I do the same as what you described and make sure the bus is idle for at least some time (dependent on the node priority) before transmitting. However, I do not have to explicitly wait for this time. Since I also read from the bus, the software just notes down the last receive ms time. Before transmitting one can see how long the bus has been idle and only wait if needed. In addition, this soft also detects collisions. This is achieved by reading while it is writing. Any mismatch or frame error is a sign of collision. In this case transmission will stop and can be retried sometimes later. (I have to admit that I should still ‘bench-mark’ the collision detection when transmitters are spread over large distances).
This soft uses the Tx/Rx lines of the integrated USART of the Atmega, so there is no need for a softSerial class. As I also want to be able to talk to the Arduino over the normal RS232 (Tx/Rx) lines, it needs full control over the individual RS485 TE/RE enable. Like this I can reload the Arduino from the IDE and start up in RS232 mode, and interact with it over USB/RS232. The program can then switch programmatically to the RS485 mode. When writing to RS232/RS485, the data will always be visible on RS232/USB, however, one cannot read from both UBS/RS232 and RS485/RS232.
I think that the soft can be adapted to CAN bus transceivers, but as said above for full functionality there need to be control over the Rx and Tx enable lines, not all CAN transceivers have them. Without this control, you will lose the flexibility to transparently upload a new application from the IDE. A clumsy solution would be based on jumpers which you change before and after reloading the program.
Last remark, this software implement a bare message transport with some primitives for address based message filtering. One can probably implement a higher level protocol on top of it. This is however, not my highest priority right now.
But I would be interested in a reference to any public domain CAN controller software for the Arduino for comparison.
Gr. Michael