How Modbus RTU carries many readings and settings from several devices over one RS-485 pair.
One device on the bus is the master (also called the client) — usually the controller. Every other device is a slave (also called a server), and each has its own address. Only the master starts a conversation: it sends a request to one address, and only the device with that address answers. Devices never speak unprompted, so the master reads each device in turn, over and over — this is polling.
Each request names a function code — what to do — and the registers to do it to:
| Function code |
Action |
| 01 |
Read coils |
| 02 |
Read discrete inputs |
| 03 |
Read holding registers |
| 04 |
Read input registers |
| 05 |
Write a single coil |
| 06 |
Write a single holding register |
| 15 |
Write multiple coils |
| 16 |
Write multiple holding registers |
A device’s data is laid out in four tables:
| Table |
Size |
Access |
Conventional numbering |
| Coils |
1 bit |
Read and write |
0xxxx |
| Discrete inputs |
1 bit |
Read only |
1xxxx |
| Input registers |
16 bits |
Read only |
3xxxx |
| Holding registers |
16 bits |
Read and write |
4xxxx |
A register map is the device manufacturer’s list of what each register holds: its address, its type, its units or scaling, and whether it can be written. Without it, the numbers on the bus mean nothing.
Things that trip people up when reading a register map:
- Numbering versus wire address. Datasheets often write holding register 1 as 40001. The address actually sent on the bus starts from 0, so 40001 is wire address 0 and 40010 is wire address 9. Check which convention a map uses; an off-by-one error reads the wrong value without any error.
- Values bigger than 16 bits. A 32-bit integer or a floating-point value takes two registers. Manufacturers disagree on which register holds the high half — the word order, often written ABCD or CDAB. The wrong order gives a nonsense value, not an error.
- Scaling. Many devices send an integer with an implied decimal point — for example 725 meaning 7.25 pH. The register map says how to scale it.
Every message ends with a CRC checksum, and a gap of silence at least 3.5 characters long marks the end of a message. A device that receives a corrupted message ignores it, and the master times out and tries again. A device that receives a valid request it cannot carry out returns an exception — for example 02, illegal data address, or 03, illegal data value.
General good practice for any RS-485 bus: observe polarity, keep the chain linear rather than a star, and terminate both ends of the segment.
- Cable. Use shielded twisted-pair cable for the two data lines, with a third conductor for the signal common (0 V). The common matters: RS-485 receivers tolerate only a limited voltage difference between devices.
- Polarity. The two data lines are labeled differently by different manufacturers — A/B, +/−, D1/D0, or TX+/TX−. Worse, some label them the opposite way round. If a device does not answer, swapping its two data wires is a legitimate test.
- Daisy chain. Run the cable from device to device in a single line. Keep any branch (stub) from the main line to a device as short as possible. Star and tree wiring cause reflections that corrupt messages, often only intermittently.
- Termination. Fit a resistor matching the cable’s impedance — typically 120 Ω — across the data pair at each of the two physical ends of the line, and nowhere else. Many devices and controllers have a built-in terminator you switch on at the ends only.
- Biasing. When no device is transmitting, pull-up and pull-down resistors hold the line in a known idle state so receivers do not read noise as data. Biasing is applied once per bus, usually at the master.
- Device count. A standard RS-485 segment supports 32 unit loads — 32 standard devices. Many modern transceivers present a quarter or an eighth of a unit load, allowing more. Beyond that, use a repeater.
- Length. A segment can run to about 1200 m (4000 ft) at low baud rates. Higher baud rates, poor cable, and many devices reduce that.
- Shield. Ground the cable shield at one point only, usually at the master, and carry it through at each device.
¶ Addresses and settings
- Address. Each device needs an address from 1 to 247, unique on the bus. Address 0 is broadcast — every device acts on it and none replies — and 248–255 are reserved. Two devices with the same address answer together and corrupt each other’s replies, so neither reads reliably. Set each device’s address before connecting it to a working bus, or connect new devices one at a time.
- Baud rate. The speed of the bus, in bits per second. 9600 and 19 200 are the most common; the Modbus specification makes 19 200 the default.
- Parity. An extra check bit on each character: even, odd, or none. The Modbus specification makes even parity the default, and calls for two stop bits when no parity is used — although many devices use one stop bit with no parity.
- Data and stop bits. RTU always uses 8 data bits. Settings are often written as a shorthand, such as 8E1 — 8 data bits, even parity, 1 stop bit — or 8N1.
Every device on a bus must use the same baud rate, parity, and stop bits as the master. There is no negotiation. A device at the wrong setting cannot make sense of anything on the bus: it simply does not answer, and it looks exactly like a wiring fault. When a device is silent, check its serial settings as well as its address and wiring.
The master also allows each device a response timeout and leaves a short gap between polls. A slow device may need a longer timeout or gap than the master’s default.
A Modbus device needs power as well as data. There are two ways to provide it:
- Bus powered (also called port powered). A supply — commonly 24 V DC — runs in the same cable as the data pair, usually from the master. One cable carries everything, and the master can restart a device by switching that supply off and on. The supply must be sized for every device it feeds, and on long runs the voltage drop along the cable must leave each device enough voltage to run.
- Externally powered. The device has its own supply, such as a local DC supply or mains. Only data travels on the bus. The device keeps running whatever happens to the master, and the master cannot restart it by removing power.
Either way, the data lines need a common 0 V reference between all devices. With externally powered devices, connect the signal common conductor, or use devices with isolated RS-485 interfaces.
Controllers differ in what their port can supply and in how they use bus power — see the controller’s own page.
- Modbus Organization — Modbus Application Protocol Specification, and Modbus over Serial Line Specification and Implementation Guide
- TIA — TIA-485-A, the RS-485 electrical standard