MODBUS is a widely used industrial communication protocol that defines an information frame structure, allowing device controllers to identify and use data. It operates independently of the physical layer and can be implemented across various network types. The protocol identifies communication participants as "master" and "slave," with data exchange following a master-slave model. In a standard MODBUS network, devices communicate directly, with smart devices connected via an asynchronous serial bus. Only one controller acts as the master, while others function as slaves. Communication follows a command/response pattern: the master initiates a request, the slave responds, and only the addressed slave responds to the master's commands.
Due to its low development cost and ease of use, MODBUS has become a recognized standard in industrial automation. Many PLCs, displays, and control devices support MODBUS interfaces, making it easy to integrate products from different manufacturers into a unified network for centralized monitoring and control.
Originally designed for PLC communication, MODBUS uses 24 bus commands to exchange data with external devices. These commands mainly handle analog input/output (AI/AO) and digital input/output (DI/DO). However, many MODBUS devices do not respond to all commands but only process those relevant to their functions.
1. MODBUS Communication Format
The MODBUS protocol supports two transmission modes: RTU (Remote Terminal Unit) and ASCII. In RTU mode, each byte is sent as an 8-bit character, while in ASCII mode, it is represented by two ASCII characters. For example, the value "20" in RTU mode becomes "00100000," whereas in ASCII, it is represented as "00110010" + "00110000" (the ASCII codes for '2' and '0'). This makes RTU significantly more efficient than ASCII when transmitting large amounts of binary data. ASCII is typically used for text-based communication, while RTU is preferred for high-speed, binary data exchanges.
The master station can send a communication request to one or all slave stations at once. It addresses the target device using the address field in the message frame. The message format includes the slave address, function code, data field (start address, number of data points, and actual data), and a CRC check. The response from the slave follows a similar structure. MODBUS also defines error codes to indicate issues during communication, allowing the master to take appropriate actions based on the error type.
MODBUS Function Codes
2. Implementation of CRC Check
In RTU mode, the last two bytes of the message contain a 16-bit CRC (Cyclic Redundancy Check) code. The sender calculates this code by performing XOR operations on the address, function code, and data fields. The receiver performs the same calculation and compares it with the received CRC. If they match, the communication is considered valid; otherwise, an error is reported.
CRC-16 is commonly used in RTU mode, with the low byte transmitted first, followed by the high byte. There are two ways to implement the CRC check: using the CRC definition formula or a lookup table. The former is often easier to implement in software. The generator polynomial used is X¹ⶠ+ X¹ⵠ+ X² + 1, which corresponds to the hexadecimal value 0x18005. The initial value for the CRC register is set to 0xFFFF, and after processing all data bytes, the final CRC value is calculated and appended to the message.
3. Link Characteristics
The MODBUS protocol can operate over various physical layers, including RS-232, RS-422, and RS-485. RS-485 is commonly used for long-distance communication due to its robustness and ability to support multiple devices on a single bus. In RTU mode, shielded twisted-pair cables are used, enabling communication distances up to 1000 meters and supporting up to 31 slave devices on one bus.
Communication is half-duplex, meaning only one device can transmit at a time. The master waits for the slave's response before sending the next command, preventing conflicts on the communication line. The RTU mode uses a specific transmission format: 1 data bit, 2 stop bits, and no parity bit. Data integrity is ensured through the CRC-16 check. A receiving device detects the start of a frame based on the time between received characters. If no new characters arrive within 3.5 character times, the frame is discarded, and the next character is treated as the start of a new frame.
Copper-Clad Aluminum Core Wire,Copper Clad Aluminum Metal Wire,Copper Clad Aluminum Pure Copper Wire ,Copper Clad Aluminum Bimetallic Wire
changzhou yuzisenhan electronic co.,ltd , https://www.ccs-yzsh.com