

In the field of industrial automation, the Modbus protocol has become the core standard for communication between devices due to its simplicity and wide compatibility. The Modbus function codes serve as the “instruction set” of the protocol, defining the types of commands between master and slave devices and determining the specific operations performed by the devices. This article systematically analyzes the definitions, classifications, application scenarios, and selection considerations of Modbus function codes, helping readers efficiently build industrial communication systems.
1. Definition and Classification of Modbus Function Codes
Modbus function codes are command identifiers sent from the master device to the slave device, typically represented as a single byte (8 bits), ranging from 0x01 (1) to 0x7F (127). Common function codes are concentrated between 0x01 and 0x10, and can be divided into two main categories based on operation type: Data Reading and Data Writing.
1. Data Reading Function Codes (0x01-0x04)
-
0x01 Read Coil Status is used to read the on/off status of digital outputs (DO) (e.g., relay, indicator light status). The master device specifies the coil address range, and the slave device returns a status array. Example: Read the switch status of a light controlled by a PLC using 0x01.
-
0x02 Read Discrete Inputs functions similarly to 0x01 but targets the read-only status of digital inputs (DI) (e.g., sensor switch signals). Example: Read the trigger signal of a safety light curtain.
-
0x03 Read Holding Registers is one of the most commonly used Modbus function codes, used to read analog data (e.g., temperature, pressure values), supporting 16-bit unsigned integers. Example: Read real-time data from a temperature sensor.
-
0x04 Read Input Registers is similar to 0x03 but targets read-only registers (e.g., device measurement data or fixed parameters). Example: Read the cumulative electricity consumption from a power meter.
2. Data Writing Function Codes (0x05-0x10)
-
0x05 Write Single Coil controls the on/off state of a single digital output (e.g., start a motor, close a valve). Example: Control the start/stop of a single motor using 0x05.
-
0x06 Write Single Register modifies the value of a single register (e.g., set the control valve opening to 50%). Example: Adjust the output frequency of a variable frequency drive.
-
0x0F Write Multiple Coils allows batch modification of continuous coil statuses, reducing communication times and improving efficiency. Example: Simultaneously control the start of multiple motors.
-
0x10 Write Multiple Registers efficiently writes data to multiple registers, suitable for complex parameter configurations (e.g., device operating modes, speed settings). Example: Configure the acceleration, deceleration, and target position of a servo motor in one go.
2. Application Cases of Modbus Function Codes
Taking a typical industrial scenario as an example: data collection from temperature sensors and pressure transmitters, and control of multiple servo motors.
- Data Collection:
- Use 0x03 to read the heating temperature of the temperature control module (holding register).
- Use 0x04 to read the real-time pressure value from the pressure transmitter (input register).
- Use 0x05 to control the start of a single motor (coil status).
- Use 0x10 to batch configure the speed, acceleration, and operating mode of the servo motors (multiple registers).
By selecting function codes appropriately, communication efficiency can be significantly improved, reducing data transmission delays.
3. Considerations for Selecting Modbus Function Codes
-
Compatibility Check Different devices may support different function codes. For example, some low-end sensors may only support 0x03 and 0x06, while high-end controllers may support all commonly used function codes. It is necessary to consult the device manual before use to avoid communication failures due to unsupported function codes.
-
Communication Efficiency Optimization Batch operations (e.g., 0x0F, 0x10) can reduce the number of communications, improving system response speed. For example, when controlling 10 motors, using 0x0F can reduce communication volume by 90% compared to 0x05.
-
Error Handling Mechanism When a slave device cannot execute a command, it will return an exception code (e.g., function code not supported, address out of range). The master device program must capture and handle these exceptions to avoid system crashes. For example, if the device returns an “illegal function code” exception, it is necessary to check whether the command is correct or whether the device supports that function.
4. Conclusion
Modbus function codes are the “linguistic foundation” of industrial communication, covering all scenarios from simple switch control to complex parameter configuration. Mastering the classification, application, and selection principles of function codes can not only enhance device interaction efficiency but also simplify troubleshooting processes. In practical projects, it is recommended to flexibly select function codes based on the device manual and communication requirements, and to build a robust error handling mechanism to create an efficient and stable industrial automation system.

Recommended Reading:
Next-Generation SCADA Configuration Software: Opening a New Era of Intelligent Factory Management
SCADA Systems: The “Smart Eye” of Factories for Efficient Operations
SCADA and HMI: The Golden Partners in Industrial Automation
IIoT Empowering Smart Factories: Driving a New Era of Industry 4.0
Industry 4.0: The Future of Manufacturing Productivity and Growth
Embracing Industrial IoT (IIoT): Eight Reasons to Drive Business Transformation and Innovation