How does Modbus RTU work?
The Modbus protocol is basically a system that processes requests and responses from electronic devices. The master/slave architecture is used with the master making requests that are responded to by the slave devices.
What is a Modbus RTU master?
A Modbus RTU master is the central device that makes requests for information from the connected slave devices. A central controller in an automated production system can play the role of a Modbus RTU master. A Modbus implementation has one master. Master devices obtain information from the slaves and can also write to the registers of the slave devices.
What is a Modbus RTU slave?
The Modbus RTU slave is the device that responds to the request made by the master device. It cannot initiate information transfers and is in a holding pattern until responding to a request made by the master.
As stated, there is one master device in a Modbus RTU implementation and there can be up to 247 slave devices. Each slave device is identified by a slave address of from 1 to 247.
At the heart of the Modbus protocol is the component known as the Protocol Data Unit (PDU). The PDU consists of a function code and data and is constructed consistently regardless of the Modbus transmission mode used. The function code specifies what data is being requested by the master.
In the Modbus RTU transmission mode, additional information is wrapped around the PDU to create the full Application Data Unit (ADU). In the signal stream and before the function code, in Modbus RTU mode a slave ID of 1 byte is sent to identify the slave device that should satisfy the request. Appended to the PDU is a 2 byte CRC which makes sure that the right amount of bytes were sent and received.
Modbus devices support four data tables which are used to facilitate communication between devices. They are Discrete Inputs, Discrete Outputs (Coils), Input Registers, and Holding Registers. The registers perform different functions and are not all included in every device. In some cases, only the holding registers are used for I/O functionality.
|used as inputs
|used to control discrete
|used for input
|used for a variety of things including inputs, outputs, configuration data, etc.
Function codes indicate how the master interacts with the slave device specified in the slave ID. Based on the function code sent, the master device may read one of the slave’s registers, or write to them.
Slaves return error codes when they receive a packet that contains an error in the request. Error codes are returned for issues such as the request for an illegal function, illegal register addresses that cannot be reached by the specified slave, and messages indicating that the slave device is busy or has experienced a failure.
Modbus RTU requires that you know or define parameters such as baud rate, character format (8 bits no parity, etc), and slave ID when initiating communication. A mismatch in any of these parameters will result in the failure of your communication attempt.