When reading through the Modbus protocol, we often encounter some easily confused terms, which can lead to problems in interpreting the protocol. In this article, we will provide relevant explanations for the terms that may cause confusion in the Modbus protocol.

1. Function code:
Function codes are used in the Modbus protocol to represent the functions of information frames. Commonly used function codes include 03, 04, 06, 16, etc. Among them, the 03 function code is used to read and hold the contents of the register, the 04 function code is used to read the contents of the input register (the difference between input register and hold register is explained below), the 06 function code is used to preset a single hold register, and the 16 function code is used to preset multiple hold registers.
2. Input register and hold register:
The function of the 04 function code is to read the input register, while the function of the 03 function code is to read the hold register. Many people always hope to find the difference between these two function codes when they see them. What is the difference between the hold register and the input register, The Modbus protocol was originally used to solve communication protocol problems in PLCs, mainly for inputting and outputting digital and analog signals. The so-called input register is derived from the analog signal input, that is, the input register can only be changed from the analog signal input terminal to the register, and the host cannot change the data of the input register by issuing instructions. The hold register is used to output analog signals, and the host can change the register data. That is to say, for the host, the input register is read-only, while the hold register can be read and written. When the host uses instructions with 06 or 16 function codes to preset the input register, the device will return an error code of 0x81, which attempts to write the read-only register.
3. Data address format in Modbus:
In the Modbus protocol, registers such as 3xxxx and 4xxxx often appear, indicating the data types supported by the registers. We use a list to illustrate, and the Modbus data address format starts from 0. For example, the following register 40009 represents the hold register, with a register address of 00 08. Similar data address formats are often used in configuration software and PLC systems.
| mapped address | Function code used | Address Type | Access method | Description |
| 0XXXX | 01,05,15 | Discrete output | read and write | Each volume represents a single switch position |
| 1XXXX | 02 | Discrete Input | read-only | Each volume represents a single switch position |
| 2XXXX | 03,04,06,16 | Floating point register | Read only/read-write | Two consecutive 16 bit registers represent a floating-point number |
| 3XXXX | 04 | input register | read-only | Each register represents a 16 bit unsigned integer |
| 4XXXX | 03,06,16 | holding register | read and write | Each register represents a 16 bit unsigned integer |
| 5XXXX | 03,04,06,16 | ASCII Characters | read and write | Each register represents two ASCII codes |
4.Modbus RTU/ASCII/TCP:
The Modbus protocol was originally used for communication between programmable logic controllers (PLCs), and due to its openness, it was widely used in field intelligent instruments. There are multiple variants of the Modbus protocol, among which the most famous isModbus RTU/Modbus ASCII and Modbus TCP communication protocols. The RTU/ASCII protocol is based on serial port communication, while the TCP protocol is based on Ethernet communication.
5. Modbus Error Code Table:
Modbus has function codes, checksum codes, exception function codes, and error codes, among which exception function codes and error codes are easily confused. Generally speaking, an abnormal function code refers to the corresponding abnormal function code that occurs during the execution of a certain function code. It is usually added with 0x80 on the basis of the function code. For example, the abnormal function code that appears in the 03 function code is 0x83, and the abnormal function code that appears in the 16 function code is 0x90. The error code indicates the specific situation where an error occurs, such as the absence of a register address, whether it is read or written. If the register address does not exist, the error code is 02.
Leave a Reply