Modbus function code/exception function code/error code
Modbus is a widely adopted serial communication protocol for electronic device communication, particularly in industrial environments. It supports multiple data transmission modes including ASCII and RTU (Remote Terminal Unit). The protocol implements various operations through Function Codes, such as reading hold registers, writing individual registers, and monitoring input statuses. Additionally, Modbus defines a set of Exception Codes and error codes to handle communication errors or abnormal conditions during data exchange.
Ⅰ.Function Codes
01 (0x01) - Read Holding Registers
02 (0x02) - Read Input Registers
03 (0x03) - Read Holding Registers
04 (0x04) - Read Input Registers
05 (0x05) - Force Single Register
06 (0x06) - Preset Multiple Registers
15 (0x0F) - Force Multiple Registers
16 (0x10) - Report Server ID
22 (0x16) - Mask Write Register
23 (0x17) - Read/Write Multiple Registers
24 (0x18) - Read FIFO Queue
26 (0x1A) - Diagnostics Register

Ⅱ.Exception Codes
When a request cannot be executed, the Modbus device returns an exception response containing an exception function code. Typically, the exception function code appears in the first byte of the response, immediately followed by the actual code value.
0x01 - Illegal Function
0x02 - Data Address
0x03 - Data Value
0x04 - Slave Device Failure
0x05 - Acknowledge
0x06 - Slave Device Busy
0x07 - Gateway Path Unavailable
0x08 - Target Device Failed to respond

III.error code
In practice, beyond abnormal function codes, other types of error codes may also occur, particularly at the hardware or software level. These errors may stem from implementation details of the Modbus protocol, physical connection issues, electrical interference, or other hardware malfunctions. For instance:
①CRC errors: In RTU mode, a failed CRC checksum indicates potential data corruption during transmission.
②Device unresponsiveness: When attempting communication with a slave device, failure to receive a response may indicate equipment malfunction, connection issues, or configuration errors.
③Overload/Timeout: When attempting to execute an operation, a timeout error may occur if the device fails to respond promptly due to excessive load or prolonged processing time.

Troubleshooting Step:
①Check Connections: Ensure all connections are correct and free from physical damage.
②Testing slave devices: Verify device responsiveness using various tools or basic Modbus commands.
③Configuration verification: Ensure Modbus address, baud rate, and other configuration settings are correct.
④Software and firmware updates: Ensure that all relevant devices have the latest software and firmware versions.
⑤Electrical interference testing: Use shielded cables or filters in areas where electrical interference is likely.
The aforementioned methods enable effective diagnosis and resolution of issues encountered during Modbus protocol implementation.










