In fields such as industrial control, power communications, and smart instruments, serial communication is usually used for data exchange. The initial method used was the RS232 interface. Due to the complexity of the industrial site, various electrical equipment will produce a lot of electromagnetic interference in the environment, which will lead to signal transmission errors.
In 1979, Schneider Electric developed a bus protocol Modbus protocol for industrial fields. Nowadays, many RS485 communication situations in industry use the Modbus protocol, so today we will learn about RS485 communication and Modbus communication protocol.
1. Introduction to RS485
In industrial control situations, the RS485 bus is widely used due to its simple interface, convenient networking, and long transmission distance.
RS485 and RS232 are both communication interfaces based on serial ports. The operations of data sending and receiving are the same, so they use the same underlying driver of WinCE. However, their communication modes are very different in practical applications. The RS485 interface is a half-duplex data communication mode, while the RS232 interface is a full-duplex data communication mode. The sending and receiving of data cannot be performed at the same time. In order to ensure that there is no conflict in the sending and receiving of data. , the hardware is implemented through direction switching, and accordingly the software also requires that the sending and receiving processes must be strictly separated.
The half-duplex network composed of the RS485 interface is generally a two-wire system (there used to be a four-wire connection method, which could only achieve point-to-point communication, but is rarely used now), and mostly uses shielded twisted pair transmission. This wiring method is a bus topology, and up to 32 nodes can be connected to the same bus. In the RS485 communication network, the master-slave communication method is generally used, that is, one host has multiple slaves.
Features of RS485:
- Electrical characteristics of RS485: Logic “0” is represented by the voltage difference between the two lines being (2-6) V; logic “1” is represented by the voltage difference between the two lines being – (2-6) V. The interface signal level is lower than that of RS232, which makes it less likely to damage the chip of the interface circuit. Moreover, the level is compatible with the TTL level and can be easily connected to the TTL circuit.
- The maximum data transmission rate of RS485 is 10Mbps.
- The RS485 interface uses a combination of a balanced driver and a differential receiver, which has enhanced anti-common mode interference capabilities, that is, good anti-noise interference.
- The standard maximum transmission distance of the RS485 interface is 4000 feet (about 1219 meters), which can actually be up to 3000 feet. In addition, the RS232 interface only allows one transceiver to be connected to the bus, which is a single station capability. The RS485 interface allows up to 128 transceivers to be connected to the bus. That is, it has multi-station capability, so users can easily establish a device network using a single RS485 interface.
2. Introduction to MODBUS
Modbus was invented in 1979 by Modicon (now a brand of Schneider Electric) and is the world’s first bus protocol truly used in industrial fields.
ModBus network is an industrial communication system, which consists of a programmable controller with an intelligent terminal and a computer connected through public lines or local dedicated lines. Its system structure includes both hardware and software. It can be applied to various data collection and process monitoring applications.
ModBus features:
- Standard and open, users can use the Modbus protocol for free and with confidence, without paying license fees and without infringement of intellectual property rights. Currently, there are more than 400 manufacturers supporting Modbus and more than 600 products supporting Modbus.
- Modbus can support a variety of electrical interfaces, such as RS-232, RS-485, etc., and can also transmit on various media, such as twisted pair, optical fiber, wireless, etc.
- The frame format of Modbus is simple, compact, and easy to understand. It is easy for users to use and easy for manufacturers to develop.
MODBUS communication transmission method:
The communication transmission is divided into independent information headers and encoded data sent. The following communication transmission method definitions are also compatible with the MODBUS RTU communication protocol:
Initial structure = ≥ 4 bytes time
Address code = 1 byte
Function code = 1 byte
Data area = N bytes
Error checking = 16-bit CRC code
end structure = ≥ 4 bytes time
Address code: The address code is the first byte transmitted by communication. This byte indicates that the slave with the address code set by the user will receive the information sent by the master. And each slave has a unique address code, and the response feedback starts with its own address code. The address code sent by the master indicates the slave address to be sent to, and the address code sent by the slave indicates the slave address sent back.
Function code: the second byte transmitted by communication. ModBus communication protocol defines function numbers from 1 to 127. This instrument only uses part of the function codes. Sent as a host request, the function code is used to tell the slave what action to perform. As a slave response, the function code sent by the slave is the same as the function code sent from the master, and indicates that the slave has responded to the master for operation. If the highest bit of the function code sent by the slave is 1 (for example, the function code is greater than 127), it means that the slave does not respond to the operation or there is a sending error.
Data area: The data area is different according to different function codes. The data area can be an actual value, a set point, or an address sent from the master to the slave or from the slave to the master.
CRC code: a two-byte error detection code.
3. The difference between RS485 and MODBUS
RS485 is a physical interface, simply speaking, it is hardware.
MODBUS is an international standard communication protocol, used for exchanging data between devices from different manufacturers (generally for industrial purposes); the so-called protocol can also be understood as the “language” someone mentioned above, or simply software.
Generally, two devices transmit data through the MODBUS protocol:
RS232C was first used as the hardware interface (that is, the serial communication port (serial port) on an ordinary computer); RS422 is also used, and there is also the commonly used RS485. This interface has a long transmission distance and is often used in general industrial sites.
The MODBUS protocol is divided into three modes: MODBUS RTU, MODBUS ASCII and the later developed MODBUS TCP: the physical hardware interfaces used by the first two (MODBUS RTU, MODBUS ASCII) are serial communication ports (RS232, RS422, RS485 ).
MODBUS TCP is designed to comply with the development trend of today’s world. Everything can be connected using Ethernet or the Internet to transmit data. So in MODBUS TCP mode, the hardware interface of this mode is the Ethernet port, which is the network port commonly used on our computers.