简体   繁体   中英

RS485: simple and reliable protocol

I'm trying to design a simple and reliable master/slaves protocol for a 2-wires RS485 bus.

All the nodes on the bus have a unique address. One node is the master that is the only node that is able to start communications. All other nodes can't send anything until the master sends a request to them.

I was thinking on simple "request/response" protocol: the master sends a request to a slave and wait for its answer. After that, M sends a request to another slave. Three scenarios could happen.

  1. Both frames (request and response) are correctly received by the destination and the transaction ends with no problem.
  2. The request from the master isn't received by the slave (checksum error). After a timeout, the master sends again the request. No problem.
  3. The response from the slave isn't received by the master (checksum error). After a timeout, the master could send again the request.

IMHO, the last scenario is problematic. The slave isn't able to understand if the second request is exactly the same of the first, so it processes the request two times. What happens if the request is "move the motor two steps", "give me if a switch is pressend since last request", "toggle a relay", and so on?

I think the simplest "request/response" protocol can't work well, except if the application level knows the limitations of the protocol and avoids requests that are dangerous if transmitted two times.

Have you some good simple and reliable protocol to suggest? I don't want to reinvent the wheel.

I've recently come across HDLC on here as I was looking for something similar. It has an operating mode that may fit your needs. Normal Response Mode (NRM) is what you described: request/response only from the master. There is an open source HDLC framer that you may be able to use as the basis of the protocol. I am considering using this myself, but there still seems to be a fair amount that is left to the project developer to implement.

This is the answer I came across that pointed me in the direction of HDLC.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM