RS485 Interface Introduction
RS485 is a serial communication interface standard renowned for its high speed, long-distance transmission, interference resistance, and multi-device sharing capabilities. It finds extensive application in industrial automation, smart homes, security systems, and other fields. This article provides a detailed overview of the RS485 interface's principles, circuit design, communication protocols, and solutions to common issues.
RS485 Principle
The RS485 interface employs differential transmission, utilizing two signal lines (A and B) to carry voltage level signals. The signal magnitude depends on the voltage difference between these two lines. In the RS485 interface, both A and B signal lines can function as either transmitters or receivers. This differential transmission method enables the RS485 interface to effectively resist external noise and interference, thereby ensuring transmission quality.
RS485 Application Fields
The RS485 interface is widely used in scenarios requiring long-distance, high-speed, and stable data transmission, such as industrial automation, smart homes, and security systems. In terms of transmission distance, RS485 supports up to 1200 meters, and in terms of transmission speed, it supports up to 10Mbps. This makes the RS485 interface widely applicable in scenarios involving data acquisition, regulation, monitoring, and control.

RS485 Circuit Design
The circuit design for an RS485 interface requires consideration of multiple factors, such as transmission distance, communication speed, lightning protection, and isolation. Below, we will introduce the circuit design for an RS485 interface from each of these aspects.
Transmission Distance
Due to its differential transmission, the RS485 interface supports longer transmission distances. However, in practical applications, factors such as transmission line impedance, crosstalk, and signal quality impose limitations on transmission range. To minimize signal loss and distortion, we generally recommend limiting the transmission distance to within 1.2 km when designing RS485 interface circuits.
Communication Speed
The RS485 interface can achieve communication speeds up to 10Mbps. In practical applications, we generally select an appropriate communication rate based on specific conditions. Higher communication speeds increase transmission efficiency but also enhance the complexity and technical demands of the interface circuitry.
Lightning Protection
Given the complex industrial environment, RS485 interfaces frequently encounter various disturbances such as lightning strikes, static electricity, and surges. To safeguard RS485 interface circuits, lightning protection measures are essential. Components like adjustable overvoltage protectors and metal oxide varistors (MOVs) can be employed to achieve lightning strike protection.
Isolation
In certain scenarios, isolation between the RS485 interface and other circuits is required. This can be achieved using components like optocouplers or magnetic couplers to isolate signals. This effectively prevents potential ground loops and noise interference, enhancing the reliability and stability of the interface circuitry.
RS485 Communication Protocols
In practical applications, RS485 interfaces also require protocol specifications and data formatting. Common RS485 communication protocols include Modbus, Profibus, and CANopen. Each protocol possesses distinct characteristics and applicable scenarios, allowing selection based on specific requirements. Below, we primarily introduce the Modbus RTU protocol, which is the most widely used transmission protocol in our projects based on RS485 interfaces.
Introduction to Modbus RTU
Modbus RTU is a widely adopted industrial communication protocol, one of the serial communication protocols based on the Modbus framework. Primarily used for serial communication between devices such as PLC controllers, sensors, and actuators, this protocol facilitates data exchange. This article details the specific meanings of each register within the Modbus RTU protocol, provides data transmission and reception examples for each function code, and highlights the crucial CRC checksum.
Modbus RTU Protocol Data Format
The Modbus RTU protocol utilizes serial communication for data transmission.
Specifically:
The Address field identifies the slave device address in communication, which can be any value between 0 and 247.
The Function Code specifies the data type and read/write direction, typically an integer between 1 and 127.
The Data Field contains the actual data content.
The Checksum (CRC) verifies the integrity of the data packet.
Modbus RTU Protocol Function Codes
In the Modbus RTU protocol, different function codes represent distinct data types and read/write directions. Below are commonly used function codes and their meanings:
01: Read coil register
02: Read discrete input register
03: Read hold register
04: Read input register
05: Write single coil register
06: Write single hold register
15: Write multiple coil registers
16: Write multiple hold registers
Modbus RTU Protocol Address Registers
Device addresses and register addresses are critical parameters for communication in the Modbus RTU protocol. Address registers can be categorized into the following four types:
Coil Register (Coil Register)
Coil registers store Boolean values (0 or 1). The function codes 01, 05, and 15 are permitted for operating on coil registers. Each coil's state can be represented by a single binary bit.
For example, if the coil at bit 0x0001 is set to 0, its binary value is 00000000 00000001. If the coil is set to 1, its binary value changes to 00000000 00000010.
Discrete Input Register
The Discrete Input Register stores the values of binary input switches and is read-only, with the corresponding function code being 02. The difference between the Discrete Input Register and the Coil Register is that it indicates whether a switch is in the ON state, rather than its current state.
Holding Register
The Holding Register stores 32-bit integer variables. Function codes 03, 04, 06, and 16 permit read/write operations on the Holding Register. Values within the Holding Register can facilitate data transfer between devices or be customized by users as relevant control parameters.
Input Register
Input registers store 32-bit integer variables and support read-only operations with function code 04. Similar to holding registers, values in input registers can be transferred between devices but cannot be modified by users.
Modbus RTU Protocol CRC Check
To ensure the reliability of Modbus RTU protocol communication, this protocol employs a Cyclic Redundancy Check (CRC) method to verify the integrity of data packets. The CRC check code is calculated based on the transmitted and received data packets and is verified simultaneously at both the sending and receiving ends.
Taking the read hold register (Function Code: 03) as an example, the hexadecimal values of the CRC checksum for its transmitted and received data packets are 0x39 and 0x3E, respectively. The specific transmitted and received data packets are as follows:
Transmitter-sent data packet: 01 03 00 00 00 01 C4 0B
In this packet, the first 6 bits (01 03 00 00 00 01) represent the Modbus RTU protocol format, while the last two bits (C4 and 0B) constitute the CRC checksum.
Received packet at the receiver: 01 03 02 00 01 39 3E
In this data packet, the first 6 bits 01 03 02 00 01 39 represent the received holding register value (two bytes), while the last two bits 3E and 39 are the calculated CRC checksum.
Modbus RTU Protocol Transmission Example
The following is a simple Modbus RTU protocol transmission example for reading data from a device's holding register:
Transmitter sends: 01 03 00 00 00 02 C5 9A
Receiver receives: 01 03 04 00 00 00 66 CB
This example reads the hold register of device 01 using function code 03, accessing the two bytes at register address 0x0000. Thus, the received data packet contains the values 0x0000 and 0x0000, i.e., 0x0000 0000, represented in hexadecimal as 0x66CB.
Conclusion
This article primarily covers the principles, applications, circuit design, communication protocols, and troubleshooting solutions for RS485 interfaces. RS485 interfaces find extensive use in industrial automation, smart homes, security systems, and other fields. However, factors such as transmission distance, communication speed, lightning protection, and isolation must be considered to ensure the reliability and stability of the interface circuitry. Basic knowledge of the Modbus RTU protocol is introduced, including its data format, function codes, address registers, and CRC checksum. In practical applications, the Modbus RTU protocol is extensively used for communication between devices within industrial automation control systems. When reading data, particular attention must be paid to selecting the device address, register address, and function code.




