DigiKey-emag-PLCs-Vol-5

What is the Modbus protocol?

original design decision.

article focused on Modbus RTU on RS-232. In Modbus RTU, the client is the only device that requests data on the network. Servers can supply data via their internal registers. Each server has a unique address in the network, and the client uses the server’s internal register addresses to read data. Modbus RTU data frames generally consist of an eight-bit address field, an eight-bit function code, several bytes of data, and a 16-bit CRC field for error correction. Normal response frames copy the address and function code values from the response and supply the answer via the data field, which typically varies in length. Response frames also end with a CRC field. In addition to normal responses, clients can send an error frame that replaces the function code with the hexadecimal value 0x80. The error frame’s data field can contain an error code to describe what went wrong.

Modbus RTU frames

Similar to CAN, Modbus is an older yet widely used industrial communication protocol allowing data exchange between devices in a network. Read on to learn more about the protocol, its functionality, and how you can apply Modbus to your day-to-day projects.

The binary coil object type represents discrete outputs and is typically used for controlling devices. Discrete inputs are the counterpart to the coils. These binary variables represent the state of binary inputs. Input registers are 16-bit read-only registers that hold analog data such as temperature readings or other sensor values. Furthermore, holding registers are 16-bit registers that the client can read from and write to, used for transmitting general data. Finally, function codes enable the server to know what operation a client wants to perform. In Modbus RTU, function code 01 represents a read from multiple coils operation, 05 corresponds to writing a value to a single coil, 02 initiates a read from a discrete input, 04 lets the client read an input register, and function codes 03 and 06 let a client read and write holding register values.

Each request frame in Modbus RTU begins with 28 bits of silence to begin the transmission. Next, the server sends the eight-bit address of the client it wants to communicate with, followed by the eight-bit function code. Following is the data field, whose field length, contents, and meaning depend on the function code. The frame concludes with a 16-bit CRC error- correcting code followed by the end condition, which consists of 28 bits of silence on the data line. While all frames adhere to the same overall structure, the data field varies widely depending on the specific operation being performed and the quantity of coils or registers involved to read or write. Figure 1 shows a few examples of requests in Modbus RTU.

the response, and the subsequent bytes contain the requested values. However, when writing a value, the first two bytes contain the address of the modified coil, and the last two bytes in the data block contain the newly written value that must match the one found in the request. Aside from the normal response, the server can also reply with an error frame. In the normal frame, the response always repeats the function code in the request. In an error frame, the server replies with a function code of 0x80, and the response only contains a single

data byte describing the error:

field typically follows the same structure, where the first two bytes define the starting address and the next two contain either a value to write or the number of registers/ coils to read. The figure 2 shows examples of responses to these requests. Note how the address and function code remain equal in the request and matching response. Read- request responses commonly adhere to a similar structure as well, where the first data byte denotes the number of bytes in

Figure 3 shows the general composition of a Modbus RTU error frame with some common exception codes. Summary Modbus is a relatively old industrial communication standard that describes the composition and structure of messages and data types without restricting the underlying physical implementation. Common standard options for implementing Modbus include RS-232 and Ethernet. This

Across the requests, the data

Figure 3: shows the general composition of a Modbus RTU error frame with some common exception codes.

we get technical

22

23

Powered by