Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.
Ivan edited this page Jan 20, 2019 · 8 revisions

RS485-comminicator

RS485-comminicatoris a serial synchronization library for master to multi-slave communication designed to work on a RS485 bus. The main purposes of this library are:

  • Organize serial data transfer in order to avoid collisions when multiple devices uses the same shared medium (like a RS485 bus). This is done by a token-driven logic.
  • All-to-All communication: most of the libraries i've found just allow a master-slave communication. In my library a device can send a message to any other device.
  • Message integrity in order to detect when errors occurs during trnsmission. This is done by crc8 checks

Protocol description

Informations about protocol logic, with explicative diagrams can be found on the RS485-communicator serial protocol documentation.

Before start

Some settings can (or sometimes must) be customized before starting, since their default value may not be suitable for your project:

  • Token timeout must be calculated on your specific project. Wrong timeouts can lead to message collisions. See Tuning the token return timeout value
  • The serial port used by default is the native one on arduino, Serial. If you use a board with multiple serial ports available(like arduino mega) you can change this port but you need to manually edit the source code of the library.
  • The current maximum number of addressable devices is 32, but can be increased up to 255 (also check if your RS485 transceiver support this amount of devices on the bus). 32 is the default value because it save up some memory bytes ( uses 4 bytes for single device availability) while allowing to address still a quite relevant number of devices.

Protocol limitations

Current limitations to consider are:

  • A Maximum of 14 bytes can be transmitted with each message. This limit derivate from my idea/interpretation of a serial bus usage: 'medium' frequency of short control messages instead of big data packages. If you need to send large strings or data in the order of multiple kb at once, probably this library is not a valid solution. In this case, i would consider switch to ethernet. This limit is driven by some internal library defines, so it can technically changed at your discrection. But remember that longer messages use more memory and in a memory-critical environment like the arduino one this can be problematic. Again, for longer and more frequent messages, i will consider to switch to ethernet.

Extra information on arduino serial and RS485

Arduino provide a TTL serial port, suitable for short range communication. Long range communication is not supported by TTL so we have to use a more suitable way for long distance transmission. This way is the Rs485 serial protocol. Reference here: https://en.wikipedia.org/wiki/RS-485

The RS485 have some interesting features:

  • Support transmissions on cables with lenght up to 1200mt
  • High interference resistance
  • Transceiver integration is quite easy and requires just an IC and a bunch of resistors.

But lack of other features:

  • RS485 protocol is not as fast as the ethernet (and that point cannot be solved).
  • RS485 protocol describes only the phisycal layer of the OSI stack. Everithing about the device addressing and message flow is demended to the developer. This library try to manage these lacks.

About these lacks a question automatically popup:

Q: Why do you have implemented board to board communication via a dedicated serial protocol instead of using the super-stable ethernet communication and all the advantage of his protocols?

A1: Because i was fascinated from the rugged capability of this kind of transmission.

A2: Because i wanted to burn out my brain by developing something just to see if i can do it.

Classes method documentation

See the wiki page

Useful links

The RS485 design guide by TI

Analog devices circuit implementation guide

Maxim integrated guidelines for RS485 proper wiring

Translation help.

English isn't my native language, and i am aware that i may have written unclear words. If you want to contribute, a lexical and logical checkup of the written words will be very appreciated!