Analysis of the difference between RS485 communication and Modbus communication protocol

In the fields of industrial control, power communication, smart meters, etc., serial communication is usually used for data exchange. The first method adopted was the RS232 interface. Due to the complexity of the industrial site, various electrical equipment will generate more electromagnetic interference in the environment, which will cause signal transmission errors. In addition, the RS232 interface can only achieve point-to-point communication, without networking functions, and the maximum transmission distance can only reach tens of meters, which cannot meet the requirements of long-distance communication.

In the fields of industrial control, power communication, smart meters, etc., serial communication is usually used for data exchange. The first method adopted was the RS232 interface. Due to the complexity of the industrial site, various electrical equipment will generate more electromagnetic interference in the environment, which will cause signal transmission errors. In addition, the RS232 interface can only achieve point-to-point communication, without networking functions, and the maximum transmission distance can only reach tens of meters, which cannot meet the requirements of long-distance communication.

Analysis of the difference between RS485 communication and Modbus communication protocol

RS485 solves these problems. The data signal adopts a differential transmission method, which can effectively solve the common mode interference problem. The maximum distance can be up to 1200 meters, and it allows multiple transceivers to be connected to the same bus. With more and more industrial application communications, Schneider Electric formulated a bus protocol Modbus protocol for industrial field in 1979, and now many RS485 communication occasions in the industry use Modbus protocol, so today we come to understand RS485 communication and Modbus letter of agreement.

【RS485 communication】

In fact, RS232 was born before RS485, but RS232 has several shortcomings:

1. The signal level of the interface is relatively high, reaching more than ten V, which is easy to damage the chip of the interface circuit, and it is not compatible with the TTL level. Therefore, a conversion circuit must be added if it is connected to the single-chip circuit.

2. The transmission rate is limited and cannot be too high. Generally, it is the limit when it reaches tens of Kb/s.

3. The interface uses signal lines and GND to form a common ground mode communication with other devices. This common ground mode transmission is prone to interference and its anti-interference performance is relatively weak.

4. The transmission distance is limited, and it can only communicate with tens of meters at most.

5. When communicating, only two points can be communicated, and multi-machine network communication cannot be realized.

In view of the shortcomings of the RS232 interface, some new interface standards continue to appear. RS485 is one of them. It has the following characteristics:

1. Logic “1” is represented by the voltage difference between the two lines as +(2-6)V; logic “0” is represented by the voltage difference between the two lines as -(2-6)V. The interface signal level is lower than RS232C, it is not easy to damage the chip of the circuit, and the level is compatible with TTL level, and it is convenient to connect with TTL circuit.

2. RS485 communication speed is fast, and the highest data transmission rate is more than 10Mbps

3. The internal physical structure of RS485 uses a combination of a balanced driver and a sub-receiver to greatly increase the anti-interference ability.

4. The farthest transmission rate can reach about 1200 meters, but its transmission rate is inversely proportional to the transmission distance. Only the transmission rate below 100KB/s can reach the maximum communication distance. If you need to transmit at a longer distance, you can use it. relay.

5. It can be connected to the bus to realize multi-machine communication. Multiple transceivers are allowed on the bus. Judging from the existing RS485 chip, there are drivers that can connect 32, 64, 128, 256 and other different devices.

RS-485 uses balanced transmission and differential reception, so it has the ability to suppress common mode interference. RS-485 adopts half-duplex working mode, and only one point is in the sending state at any time. Therefore, the sending circuit must be controlled by the enable signal. RS-485 is very convenient when used for multi-point interconnection, and can save a lot of signal lines. The application of RS-485 can be networked to form a distributed system, which allows up to 32 drives and 32 receivers to be connected in parallel. In the equipment network formed by RS232 or RS485 equipment, if the number of equipment exceeds two, RS485 must be used as the communication medium. If the equipment of the RS485 network wants to exchange information, it can only be realized through the “Master” equipment transfer. The master device is usually a PC, and only one master device is allowed in this device network, and the rest are all slave devices.

RS485 has two-wire and four-wire connections. The four-wire system can only achieve point-to-point communication, which is rarely used now. Nowadays, the two-wire connection method is mostly used. This wiring method is a bus topology. Up to 32 nodes can be connected on the same bus. In the RS485 communication network, a master-slave communication method is generally adopted, that is, a master with multiple slaves. In many cases, when connecting the RS-485 communication link, simply use a pair of twisted pair to connect the “A” and “B” ends of each interface. The signal ground connection is ignored. This connection method can work normally in many occasions, but it has buried a lot of hidden dangers. There are two reasons:

(1) Common mode interference problem: The RS-485 interface adopts a differential transmission signal mode, and does not need to detect the signal relative to a certain reference point. The system only needs to detect the potential difference between the two wires. But people often overlook that the transceiver has a certain common-mode voltage range. The common-mode voltage range of the RS-485 transceiver is -7~+12V. Only when the above conditions are met, the entire network can work normally. When the common mode voltage in the network line exceeds this range, it will affect the stability and reliability of the communication, and even damage the interface.

(2) EMI problem: The common mode part of the output signal of the sending driver needs a return path. If there is no return channel (signal ground) with low resistance, it will return to the source in the form of radiation, and the entire bus will be like a huge The antenna radiates electromagnetic waves outward. Because the PC only has the RS232 interface by default, there are two ways to get the RS485 circuit of the PC upper computer: (1) Convert the RS232 signal of the PC serial port to the RS485 signal through the RS232/RS485 conversion circuit, which is more complicated for the industry The environment is best to choose products with anti-surge belt isolation. (2) Through the PCI multi-serial port card, the expansion card whose output signal is RS485 type can be directly selected.

【Modbus communication protocol】

Modbus protocol is a universal language applied to Electronic controllers. Through this protocol, the controllers can communicate with each other and between the controllers and other devices via a network (such as Ethernet). It has become a general industry standard. With it, control equipment produced by different manufacturers can be connected to an industrial network for centralized monitoring. This protocol defines the message structure that a controller can recognize and use, regardless of what kind of network they communicate through. It describes the process of a controller requesting access to other devices, how to respond to requests from other devices, and how to detect and record errors. It has formulated a common format for the structure and content of the message domain.

Analysis of the difference between RS485 communication and Modbus communication protocol

Modbus has the following characteristics:

(1) Standard and open, users can use the Modbus protocol for free and with confidence, without paying a license fee, and will not infringe on intellectual property rights. Currently, there are more than 400 manufacturers supporting Modbus and more than 600 products supporting Modbus.

(2) Modbus can support a variety of electrical interfaces, such as RS-232, RS-485, etc., and can also be transmitted on various media, such as twisted pair, optical fiber, wireless, etc.

(3) Modbus frame format is simple, compact and easy to understand. It is easy for users to use and easy for manufacturers to develop.

【RTU protocol frame data】

Modbus has two communication transmission modes, one is ASCII mode and the other is RTU mode. Because the data byte of ASCII mode is 7bit data bits, 51 single-chip microcomputer can not realize it, and the application is relatively small, so here we only use RTU mode. The two modes are similar, so you can use one and the other. A typical RTU data frame is shown in the figure.

Analysis of the difference between RS485 communication and Modbus communication protocol

Similar to our practical serial communication program, the data frame we send at one time must be transmitted as a continuous data stream. The method we use in the practical serial communication program is to define 30ms. If the received data exceeds 30ms without receiving the next byte, we consider the data to be over. The RTU mode of Modbus stipulates that the interval between different data frames is more than 3.5 bytes of communication time. If there is a pause of more than 3.5 bytes before the completion of a frame of data, the receiving device will refresh the current message and assume that the next byte is the beginning of a new data frame. Similarly, if a new message starts after the previous data in less than 3.5 bytes, the receiving device will consider it a continuation of the previous frame of data. This will cause an error, so everyone sees that there is a 16-bit CRC checksum at the end of the RTU data frame.

Start bit and end character: there is a time interval of at least 3.5 bytes before and after, the start bit and end character actually do not have any data, T1-T2-T3-T4 represents the time interval of more than 3.5 bytes , And the first byte that really makes sense is the device address.

Device address: When there are so many data in multi-machine communication, what do we rely on to determine which device this data frame belongs to? Yes, it depends on this device address byte. Each device has its own address. When the device receives a frame of data, the program first judges and compares the device address byte. If it is different from its own address, the frame of data is directly ignored. If you have the same address, you must parse this frame of data, and execute the corresponding function according to the function code that follows. If the address is 0x00, it is considered to be a broadcast command, which is an instruction to be executed by all slave devices.

Function code: In the second byte of the function code byte, Modbus specifies part of the function code, and also reserves part of the function code as a spare or user-defined. These function codes do not need to be memorized or even read , And check this form until the day you use it.

Analysis of the difference between RS485 communication and Modbus communication protocol

CRC check: CRC check is a data algorithm used to check whether the data is right or wrong. The CRC check function takes a frame of data except the last two bytes, and all the bytes in front are calculated by a specific algorithm. After the calculation, a 16-bit data is generated as a CRC check code and added to the end of a frame of data . After the receiver receives the data, it will also calculate the CRC of the previous byte, and compare it with the 16bit data of the sent CRC after the calculation. If the data is the same, the data is considered normal and there is no error. If the comparison is not the same, it means If an error occurs in the data transmission, this frame of data will be discarded as if it has not been received, and the sender will handle the error accordingly after receiving no response.

The Links:   2DI50Z-100 GP470-EG11

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *