Modbus is widely used due to its advantages
-
The Modbus protocol is standard, open, publicly available, and has no copyright requirements
-
The Modbus protocol supports various electrical interfaces, including RS232, RS485, TCP/IP, and can transmit over various media such as twisted pair, fiber optics, infrared, and wireless
-
The Modbus protocol message frame format is simple, compact, and easy to understand. Users find it easy to comprehend and use, making it convenient for manufacturers to develop and integrate, thus facilitating the formation of industrial control networks
Modbus Communication Process
Note that Modbus is a master-slave communication protocol
In Modbus communication, only one device can send requests. Other slave devices receive data sent by the master and respond. Slaves can be any peripheral device, such as I/O sensors, valves, network drivers, or other measurement devices. Slave stations process information and send their data to the master station using Modbus.
This means that Modbus cannot communicate synchronously; the master can only send requests to one slave at a time. Only one piece of data can be transmitted on the bus at any given moment, meaning the master sends, the slave responds, and if the master does not send, there is no data communication on the bus.
Modbus RTU is a compact way of representing data in hexadecimal, while Modbus ASCII represents data using ASCII code, with each 8-bit byte sent as two ASCII characters.
The RTU format includes a cyclic redundancy check (CRC) checksum for subsequent commands/data, while the ASCII format uses a longitudinal redundancy check (LRC) checksum.
When using serial transmission, the Modbus protocol can choose between RTU or ASCII mode, specifying the message, data structure, commands, and response methods, requiring data validation. The ASCII mode uses LRC validation, while the RTU mode employs 16-bit CRC validation. When transmitted over Ethernet, TCP is used, which does not require validation since the TCP protocol is a connection-oriented reliable protocol.
Modbus-RTU Protocol
The Modbus-RTU message structure is as follows:
-
Slave Address: Each slave has a unique address, occupying one byte, with a range of 0-255, where the valid range is 1-247, and 255 is the broadcast address (broadcast means sending a response to all slaves)
-
Function Code: Occupying one byte, the function code indicates what this command is for, such as querying data from the slave or modifying the slave’s data, with different function codes corresponding to different functions.
-
Data: Depending on the function code, there are different functionalities. For example, if the function code is to query data from the slave, this includes the address of the data being queried and the number of bytes to query.
-
Check: During data transmission, errors may occur, and the CRC check detects whether the received data is correct.
Modbus-ASCII Protocol
In the message, each byte is sent as two ASCII characters
Summary:
Modbus ASCII has start and end characters (CR LF), which can serve as markers for the beginning and end of a frame of data, while Modbus RTU does not have such markers and requires a time interval to determine the start and end of a message frame. The protocol specifies that the time interval should be greater than 3.5 character periods, meaning that before a frame of messages starts, there must be more than 3.5 character periods of idle time, and after a frame of messages ends, there must also be 3.5 character periods of idle time; otherwise, packet sticking may occur.
Modbus-TCP Protocol
Modbus-TCP does not require a slave address but requires an MBAP header and does not require error checking since TCP itself has error checking capabilities.