Modbus
Modbus is a simple, royalty-free, master/server (now client/server) protocol introduced by Modicon in 1979. It has outlived nearly every “modern” competitor because it is easy to implement, well-documented, and universally supported.
Overview
- One client (master) talks to many servers (slaves).
- Server addresses 1–247; 0 is broadcast (RTU/ASCII only).
- No native authentication or encryption — segment the network.
- Maintained by the Modbus Organization.
Variants
- Modbus RTU — binary over RS-485 / RS-232; most common in the field.
- Modbus ASCII — readable text over serial; rarely used.
- Modbus TCP — over Ethernet, TCP port 502; no CRC (TCP handles it).
- Modbus over UDP, Modbus over TLS — newer additions.
Data Model
- Discrete Inputs — 1-bit, read-only (10001–19999).
- Coils — 1-bit, read/write (00001–09999).
- Input Registers — 16-bit, read-only (30001–39999).
- Holding Registers — 16-bit, read/write (40001–49999).
- 32-bit values use 2 consecutive registers; watch endianness (big / little / mixed).
Function Codes
- 0x01 Read Coils.
- 0x02 Read Discrete Inputs.
- 0x03 Read Holding Registers.
- 0x04 Read Input Registers.
- 0x05 Write Single Coil.
- 0x06 Write Single Register.
- 0x0F Write Multiple Coils.
- 0x10 Write Multiple Registers.
- 0x17 Read/Write Multiple Registers.
Wiring & Timing
- RS-485: twisted pair, 2-wire (A/B) or 4-wire; 120 Ω termination at both ends.
- Up to 32 nodes per segment (more with low-load transceivers); 1200 m max at 9600 baud.
- Common baud rates: 9600, 19200, 38400, 57600, 115200.
- RTU inter-character silence: 1.5× char time; inter-message silence: 3.5× char time.
Troubleshooting
- Check baud, parity, stop bits match on every node.
- Verify A/B polarity (a swapped pair is the #1 symptom).
- Termination resistor present at both ends (not the middle).
- Use a Modbus poller (Modbus Poll, ModScan, mbpoll) to isolate device vs master.
- For TCP: check port 502 firewall, server unit ID, slave timeout.
- Exception codes 01–04 are the most common: bad function / address / value / device failure.