What is Modbus?
Understanding the Modbus communication protocol
- RTU, ASCII, and Modbus/TCP message formats
- Modbus function codes and instructions
- Data types and register structures
Overview
Modbus is a widely used communication protocol for exchanging data between devices in industrial automation and control systems. It enables communication between devices such as controllers, sensors, and other industrial equipment.
The protocol supports serial communication via Modbus RTU and ASCII, as well as network communication via Modbus/TCP. SEGGER's emModbus supports these protocol variants, providing a flexible solution for integrating Modbus communication into embedded applications.
Message frames
emModbus supports all three Modbus standard protocols covered by the official Modbus documentation:
| Protocol | Description |
|---|---|
| RTU | Original Modbus standard. Binary data is sent via serial connections such as RS-232 or similar. |
| ASCII | Similar to RTU. Instead of raw binary, data is encoded in ASCII. |
| Modbus/TCP | Binary data is encapsulated in a TCP frame and sent via network connections such as Ethernet. This variant can also be used with UDP instead of TCP and is then called Modbus/UDP. |
The three Modbus message frames
Instruction Set
emModbus currently supports the following instructions:
| Function code | Description |
|---|---|
| 1 | Read Coil. |
| 2 | Read Discrete Input. |
| 3 | Read Holding Register. |
| 4 | Read Input Register. |
| 5 | Write Coil. |
| 6 | Write Register. |
| 15 | Write Coils. |
| 16 | Write Registers. |
Data Types
Modbus uses four primary data types:
| Data type | Description |
|---|---|
| Coil | Single bit, alterable by an application program, read-write. |
| Discrete Input | Single bit, provided by an I/O system, read-only. |
| Holding Register | 16-bit, alterable by an application program, read-write. |
| Input Register | 16-bit, provided by an I/O system, read-only. |