How do you use RS-485?

I've never seriously looked at implementing RS-485 on arduino before. I am wondering how you use RS-485 with your arduino projects.

I know that you may be using point-to-point so there are only two devices on the bus. Then how do you arbitrate who gets to use it?

If you have multiple devices, how does each device know it is its turn to talk? Will some address be sent out first and how does each device know its own address?

I did some reading online so I know the differential signalling, some cheap RS-485 adapters such as sparkfun etc. I am not too sure how to arbitrate although there are hardware enable pins. I would like to see some actual use case other than "hey, I wired two arduinos to each other using RS-485, one is sending, the other is receiving!". Something that involves actual devices that use RS-485 would be nice!

RS-485 is just a physical serial interface standard that uses differential signaling to enable relatively long cables. It also has the ability to connect multiple devices forming a bus. In most use cases the communication is half-duplex using just one pair of wires. Because there is no hardware support to detect congestion/collision in all cases know to me there is one master on the bus, all other devices are slaves.

There are several protocol defined that use RS-485 as the physical layer, probably the best known is ModBus. But you can use any protocol, even your own to run on that physical communication channel. If you allow multiple masters on that one bus you must solve the collision problem somehow.

What then is a typical protocol for multiple slaves and one master, the modbus protocol? I'm trying to get all my terms right. Do they issue addresses before data etc? I'll be reading on modbus in the mean time.

Thanks.

1 Like

ModBus is not a general protocol but one that is optimized to read many sensors/measurement devices from one master. And yes the slaves have addresses so they know which one is called for the request.

DMX is a widely used standard for controlling lights and also relies on RS-485 as the physical layer.

PROFIBUS also uses the RS-485 as one possible physical layer and is probably the system with the broadest field of use but it is much more complex than for example ModBus.

What do you want to do with RS-485?

Thanks for the comparison Pylon. I think I am inclined to learn more about ModBus since my interest is connecting sensors. RS-485 comes up once in a while with sensors I use as one of the "interfaces/protocols" some sensors do, besides other interfaces. I'll do some reading on ModBus. Other than sensors, I just have a general interest to get some more understanding about this RS-485 stuff.

With a MAX485 breakout you can convert TTL serial to RS485 for connecting up to 32 devices over 1200m or so. It’s a half-duplex transceiver so you can’t listen to the network while you are sending.

Thanks. Do you turn off hardware RX before transmitting or do you flush all RX buffer after transmitting?

Check out Gammon's page on RS-485: https://www.gammon.com.au/forum/?id=11428

Here's a link to a modbus library for Arduino which contains several examples.

I started my home automation project using RS485 drivers and created a custom protocol to overcome some of the limitations of Modbus. In hindsight it was a lot of work for not a lot of gain.

I'm now switching to CAN bus because I found the MCP2515 chip which does all the data link layer stuff plus it has message prioritisation and filtering. I can now focus on the application layer instead of spending hours staring at an oscilloscope watching bits being truncated because of hardware timing issues.

DaveEvans:
Check out Gammon's page on RS-485: https://www.gammon.com.au/forum/?id=11428

Thanks. Bookmarked for weekend reading.

mikb55:
I started my home automation project using RS485 drivers and created a custom protocol to overcome some of the limitations of Modbus. In hindsight it was a lot of work for not a lot of gain.

I'm now switching to CAN bus because I found the MCP2515 chip which does all the data link layer stuff plus it has message prioritisation and filtering. I can now focus on the application layer instead of spending hours staring at an oscilloscope watching bits being truncated because of hardware timing issues.

Thanks. CAN bus is my next interface/protocol to learn. Will read about MCP2515 as well.