directory

1. Introduction to serial link communication

2. Principle of serial link communication protocol

3. Serial link communication frame description

4. RTU and ASCII serial transmission mode

4.1. RTU Transmission Mode

4.2 ASCII transmission mode


1. Introduction to serial link communication

The Modbus protocol standard defines the application-layer message transport protocol at layer 7 of the OSI model, which provides client/server communication between devices connected to different types of buses or networks. It also standardizes protocols over serial links to exchange Modbus requests between a master station and one or more slave stations. The purpose of this blog post is to describe Modbus protocol over serial links and to achieve intercommunication between devices.

The Modbus serial link protocol is a master/slave protocol that sits at layer 2 of the OSI model, the master/slave protocol system: there is a node (master node) that issues explicit commands to some “child” node and processes the response. A typical child node does not actively send data or communicate with other child nodes without receiving a request from the master node. Modbus protocol and ISO/OSI model are shown below:

In the physical layer, Modbus serial link system can use different hardware physical interfaces (RS485, RS232). The most commonly used is TIA/EIA-485 (RS485) two-wire interface. As an additional option, RS485 four-wire interface can also be implemented. TIA/EIA-232-E (RS232) serial interfaces can also be used when only short distance point-to-point communication is required.

2. Principle of serial link communication protocol

Modbus serial link protocol is a master/slave protocol. At any one time, only one master node is connected to the bus, and one or more child nodes (Max. 247) are connected to the same serial bus. Modbus communication is always initiated by the master node, and the child node never sends data without receiving a request from the master node. Child nodes never communicate with each other. The master node will only initiate one Modbus transaction at a time.

The master node sends Modbus requests to its children in two modes: unicast mode and broadcast mode.

Unicast mode The primary node accesses a child node at a specific address. After the child node receives and processes the request, the child node returns a message (a ‘reply ‘) to the primary node. In this mode, a Modbus transaction contains two messages: a request from the master node and a reply from the child node. Each child node must have a unique address (1 through 247) so that it can be addressed independently from other nodes. As shown below:

Broadcast mode The primary node sends requests to all child nodes, and no reply is returned for requests broadcast by the primary node. Broadcast requests are generally used to write commands. All devices must accept the write function in broadcast mode. Address 0 is used to represent broadcast data. As shown below:

Modbus addressing space has 256 distinct addresses, address 0 is reserved as the broadcast address, and all child nodes must recognize the broadcast address. The Modbus master node does not have an address, only child nodes must have an address. The address must be unique on the Modbus serial bus. The address rules are as follows:

3. Serial link communication frame description

The Modbus structure on the serial link must comply with the general Modbus frame protocol requirements, as shown below:

Specific analysis is as follows:

  • Address domain: On the Modbus serial link, the address domain contains only child node addresses. The valid child node addresses are 0-247 in decimal notation. Each child device is assigned an address in the range 1-247. The master node addresses the child node by putting its address in the address field of the message. When the child node returns a reply, it puts its address in the address field of the reply message so that the master node knows which child node is answering.
  • Function code: The function code specifies the action to be performed by the server. Function codes can be followed by data fields representing request and response parameters;
  • Data: receiving and sending data information;
  • Check: The error check field is the result of “redundancy check” performed on the packet content, usually CRC or LRC check, depending on the transmission mode (RTU or ASCII) using two different calculation methods.

4. RTU and ASCII serial transmission mode

Modbus serial link has two modes for transmitting data, RTU mode and ASCII mode. It defines the serial transmission of the bit content of the message field over the line and determines how the information is packaged as a message and decoded. The transmission mode (and serial port parameters) of all devices on Modbus must be the same to achieve normal communication.

4.1. RTU Transmission Mode

When the device uses the Remote Terminal Unit (RTU) mode to communicate over the Modbus serial link, each 8-bit byte in the packet contains two 4-bit hexadecimal characters. The main advantage of this mode is that the data density is higher than that of THE ASCII mode. In the same baud rate, the throughput rate is higher than that of the ASCII mode. Each packet must be transmitted in consecutive characters.

The format of each byte (11 bits) in RTU mode is as follows:

Encoding system: Each 8-bit Byte in an 8-bit binary packet contains two 4-bit hexadecimal characters (0-9, A-F) Bits per Byte: 1 Start 8 data Bits. The least significant bit is sent first as the parity 1 stop bitCopy the code

To ensure maximum compatibility with other products, the default RTU check mode must be even check. Every character or byte is sent from left to right. The sending device constructs Modbus packets as frames with known start and end marks. This allows the device to receive a new frame at the beginning of a message and to know when the message ends. Incomplete messages must be detected and error flags must be set as a result. In RTU mode, message frames are distinguished by idle intervals of at least 3.5 characters. In subsequent sections, this time interval is referred to as T3.5. RTC frames are as follows:

The entire message frame must be sent as a continuous stream of characters. If the idle interval between two characters is greater than 1.5 characters, the message frame is considered incomplete and should be discarded by the receiving node.

4.2 ASCII transmission mode

When devices on the Modbus serial link are configured to communicate using ASCII (American Standard Code for Information Interchange) mode, each 8-bit segment in the message is sent as two ASCII characters. This mode is used when a communication link or device cannot comply with the RTU mode. However, this mode is less efficient than RTU because a sub-section requires two characters. Example: The value 0X5B is encoded as two characters: 0x35 and 0x42 (ASCII encoding 0x35 =”5″, 0x42 =”B”).

ASCII mode Each byte (10 bits) is formatted as follows:

Each ASCII character in an A-F packet contains one hexadecimal character. Bits per Byte: 1 Start bit 7 Data bit. The least significant bit is sent first as the parity 1 stop bitCopy the code

To ensure maximum compatibility with other products, the default ASCII check mode must be even check. Each character or byte is sent in order from left to right. The sending device constructs Modbus packets as frames with known start and end marks. This allows the device to receive a new frame at the beginning of a message and to know when the message ends. Incomplete messages must be detected and error flags must be set as a result. The address field of a message frame contains two characters. In ASCII mode, a message uses a special character to distinguish the start and end of a frame. A message must start with a ‘colon **’ ** (:) (ASCII hexadecimal 3A) and end with ‘Carriage return **- newline’ ** (CR LF) pair (ASCII hexadecimal 0D and 0A). For all fields, the characters allowed to be transmitted are hexadecimal 0 — 9, A — F (ASCII encoding). The device continuously monitors the ‘colon’ character on the bus. Upon receiving this character, each device decodes subsequent characters until the end of the frame. The interval between characters in a message can be up to one second. If there is a larger interval, the receiving device thinks that an error has occurred. ASCII packet frames are shown as follows: