Detailed explanation of RS485 bus interface protocol

Today I will share an article explaining the details of the RS485 interface protocol. Thoroughly understand the RS485 bus interface protocol.

letter of agreement

The communication protocol is mainly to realize the data exchange function between two devices, and the communication protocol is divided into a hardware layer protocol and a software layer protocol.

The hardware layer protocol determines how data is transmitted. For example, to send 0x63 from device 1 to device 2, the binary number of 0x63 is 0110 0011. These 8 binary numbers are transmitted from device 1 to device 2. How to transfer 1 and how to transfer 0 This is the problem to be solved by the hardware layer.

At present, the hardware layer protocols are more common such as RS-232, RS-485, SPI, IIC and so on. RS-232 stipulates that the voltage on the line is x volts, which means that the transmission is 0, and the transmission of y volts is 1. Furthermore, for example, how many lines to choose to transmit data, and what material to choose for line transmission input, these are also constrained by the hardware layer protocol. The hardware layer protocol is also called the interface protocol.

The software layer protocol refers to the communication rules agreed by the two parties in terms of software coding. For example, if one person speaks Chinese, the other must also speak Chinese, so that they can communicate; common software layer protocols include Modbus protocol, TCP /IP protocol, GPRS, etc.; and Modbus protocol can be transmitted through serial port, RS-485, Ethernet, etc.;

The image is understood as: two people who communicate in Chinese (software protocol) can communicate in different ways (hardware protocol) such as face-to-face, phone calls, and text messages

RS-485 communication protocol

The MCU pin outputs TTL level, which means that when the MCU pin outputs 0 level, the voltage is generally 0V, and when the MCU pin outputs 1 level, the voltage is 5V.

Because the TTL level is generated by a signal line and a ground line, the interference signal on the signal line will be transmitted to the receiving end following the effective signal, causing the effective signal to be interfered. 485 communication actually passes the TTL level from the MCU A converter chip at the hardware layer performs the conversion:

Convert a TTL signal from the MCU to signals on two lines (line A, line B) through the chip.

When the MCU inputs a low TTL level to the converter, the converter will make the voltage of B higher than that of A, otherwise, the voltage of A is higher than that of B.

The 485 protocol stipulates that the difference between the two level lines indicates 0 or 1, and the voltage can be measured by an instrument, so RS-485 is a hardware layer protocol.

The receiving end of the 485 protocol may be another MCU, and the pins of the MCU only accept the TTL level, and the voltage from the conversion chip is the voltage of the two lines, so it is necessary to convert the differential voltage of the two lines to the TTL level.

Converting TTL to 485 is essentially an integrated chip without any program code, pure hardware logic. In the same way, the same is true for converting 485 level to TTL.

Nowadays, many chips integrate the receiving and converting into one IC. Note that the converter and receiver still do not work at the same time. The common converting chip is MAX485.

It can be understood that the hardware layer protocol is a road, and the purpose of the road is to allow vehicles to pass by.

half-duplex communication

First understand what simplex communication is. Simplex communication refers to a communication method in which data can only be transmitted in one direction. The half-duplex communication means that for the two ends of the communication, data cannot be sent to each other at the same time, and must be sent in a staggered time period.

RS-485 has only 2 communication lines, and these two communication lines need to be used in one transmission, so 485 can only realize half-duplex communication.

485 realizes half-duplex communication, and there will be a problem. When MCU1 sends data to MCU2, it does not know whether the data from MCU2 is being transmitted on the line, because there is no other line to judge the sending and receiving status of the other party, which may also cause data failure. conflict.

Therefore, in order to realize half-duplex communication, RS-485 needs to be regulated by the upper layer software protocol , that is, "you can't send data if you want to". It can be understood that the software layer protocol is like traffic rules, which allow data to be transmitted in an orderly manner.

Introduction to RS-485

The Electronics Industries Association (EIA) formulated and released the RS-485 standard in 1983, and it was named TIA/EIA-485-A after being revised by the Communications Industry Association (TIA), so TIA/EIA-485-A is the real name , because people are already used to calling it RS-485, so the name RS-485 has been used in the follow-up.

The RS-485 standard was created to make up for the shortcomings of RS-232 such as short communication distance and low speed. The RS-485 standard only stipulates the electrical characteristics of the balanced transmitter and receiver, but does not specify the connector, transmission cable and application layer communication protocol.

The RS-485 standard is different from RS-232. The data signal adopts a differential transmission method (Differential Driver Modc), also known as a balanced transmission. It uses a pair of twisted pairs, and one line is defined as A, and the other line is defined as B. as the picture shows.

Transmission method and level logic

RS-485 transmission mode: half-duplex communication, == (logic 1: +2V ~ +6V logic 0: -6V ~ -2V) == The level here refers to the voltage difference between the two lines AB.

Schematic diagram of node connection

Because the signals of most MCUs are TTL signals, and the data is sent and received through the serial port, which does not conform to the RS-485 standard.

Therefore, if the data is to be transmitted on the 485 communication line, it is necessary to convert the TTL signal into a RS-485 differential signal, then transmit it on the AB line, and then convert the RS-485 differential signal into a TTL signal after reaching the node. Data processing for the MCU of the node

RS-485 data link diagram

Topology

RS485 has two kinds of wiring, two-wire system and four-wire system. The four-wire system can only realize point-to-point communication mode, which is rarely used now. The two-wire system connection mode is mostly used. This wiring mode is a bus topology. Up to 32 nodes can be connected to the bus.

The RS-485 bus is the same as I2C, and it is also a master-slave mode. It supports point-to-point single-slave mode and multi-slave mode, but does not support multi-master mode.

Circuit schematic

The schematic diagram is a basic RS-485 circuit, which uses the SP3485 chip of Sipex Company, which is a low-power chip with a working voltage of 3.3V. Some features of the chip will be introduced later.

The standard serial port of the microprocessor is directly connected to the RO pin of the SP3485 chip through RXD, and is directly connected to the DI pin of the SP485R chip through TXD.

The selection bit for the chip to be in the sending mode or the receiving mode is DE/!RE. Generally, these two pins are connected together, and only one pin of the microprocessor is used for control.

U9 is a TVS tube, which can be added when the environment is harsh, for protection, and it can be omitted for normal experiments.

R25 is a pull-up resistor, and R27 is pulled down. By default, A is pulled high and B is pulled low. If no resistor is added, it is unstable by default and will interfere with the pins of the microcontroller.

 Information through train: Linux kernel source code technology learning route + video tutorial kernel source code

Learning through train: Linux kernel source code memory tuning file system process management device driver/network protocol stack

Chip internal diagram

Inside the transceiver is a receiver (top half) plus a transmitter (bottom half), and then the pin function.

RO: Receiver output RE: Receiver output enable (active low) DE: Transmitter output enable (active high) DI: Transmitter input GND: Ground connection A: Transmitter output/receiver input inverted Phase B: Transmitter output/receiver input inverted

Vcc: positive power supply (+3.3V<VCC<+3.60V)

Send function truth table

If the signal DE_nRE output by the microprocessor is high, the chip is in the sending mode (transmitter/driver), and the differential outputs A and B follow the logic state at the data input DI;

When DI is high, it causes A to go high and B to go low. In this case,  VOD=VA-VB the differential output voltage defined as is positive, that is, logic 1 (the voltage difference between AB is +2V ~ +6V);

When DI is low, the output state is reversed, B becomes high, A becomes low, VOD is negative, which is logic 0 (the voltage difference between AB is -6V ~ -2V);

When DE is low, both outputs become high impedance. In this case, the logic state at D is irrelevant.

Receive function truth table

If the signal DE_nRE output by the microprocessor is low, the chip is in receiving mode (receiver), and if it is high, the receiving mode is turned off;

When the level between A and B is greater than +200mv, the RO pin outputs logic 1;

When the level between A and B is less than -200mv, the RO pin outputs logic 0;

When the level between AB is between -200mv ~ +200mv, it means unstable

advantage

  • half-duplex communication
  • Differential signal transmission, more stable
  • The internal physical structure of RS485 adopts the combination of balance driver and detection receiver, which greatly increases the anti-interference ability.
  • Networking can be carried out on the bus to achieve multi-machine communication. Multiple transceivers are allowed to be connected to the bus. From the perspective of the existing RS485 chip, there are drivers that can connect 32, 64, 128, 256 and other different devices.
  • The communication speed is fast, and the maximum data transmission rate is above 10Mbps
  • The maximum transmission rate can reach about 1200 meters, but the 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 longer distances, you can use a relay.
  • The system runs stably. The concentrator and the main station are connected safely and reliably by using a dedicated communication bus. Unless the device interface hardware is damaged, or the bus line is disconnected, the bus meter reading system will always maintain a good communication effect and reading success rate.
  • The communication rate is high. Because it is a dedicated wired communication line connection, there are no other signals on the line except the communication signal. The external interference signal coupled to the line attenuates greatly, so the concentrator can communicate with the master station at a higher rate.

shortcoming

  • Does not support full duplex
  • Laying is difficult. For example, the bus meter reading system needs to lay communication lines between the concentrator and the master station. Especially when the energy meters are relatively scattered, the amount of engineering for laying communication lines is very large, and the external communication lines affect the appearance.
  • Maintenance costs are high. For example, the damage of the communication line directly affects the communication effect of the bus meter reading method. Therefore, it is necessary to check the line regularly to ensure its normal operation. Especially the lines erected outside, once they are broken or corroded, they need to be rewired. For newly added users, it is also necessary to lay lines in time to make them enter the communication network

Common chips

(1) Enhanced low-power half-duplex RS-485 transceiver-SP481E/SP485E

Features:

Single +5V power supply

Manufactured in low power consumption BiCMOS process

Transmitter/receiver can enable multi-drop structure (Mutli-Drop) to configure low-power shutdown mode (SP481E)

Description (SP481E, SP485E)

SP481E and SP485E are half-duplex differential transceivers that fully meet the requirements of RS-485 and RS-422. They are manufactured by Sipex's unique BiCMOS process.

The RS-485 standard is ideally used in multi-drop applications and remote interfaces. It allows up to 32 transmitters and receivers to be connected on one data line, making it ideal for multi-drop applications.

Because it allows the use of 4000 feet of cable, the RS-485 transceiver can use a wide (-7V~+12V) common mode range to adjust the zero potential deviation. Because RS-485 is a differential interface, the interference from the transmission line can be completely suppressed when transmitting data.

(2) 1/10 unit load RS-485 transceiver one SP481R/SP485R

features

Single +5V power supply

Allows more than 400 transceivers to be connected to the same transmission line (1/10 unit load) receiver input high impedance (standard value RIN=150kQ)

Half-duplex configuration conforms to industry-standard pinouts

The common mode input voltage range is -7V~+12V

Including shutdown mode (ICC<10uA) (for SP481R) low power consumption (250mW)

Independent Transmitter and Receiver Enables

SP485R chip is a high-performance RS-485 transceiver designed and produced by Sipex, a professional manufacturer of communication interface devices in the industry. It can replace the general RS-485 transceiver and has been enhanced in many aspects.

The SP481R and SP485R have the same pin-to-pin correspondence as the existing SP485 product, and include features such as higher ESD protection and high receiver input impedance.

The high impedance of the receiver input allows 400 transceivers to be connected to the same transmission line without causing attenuation of the RS-485 transmitter signal. Each device is packaged as 8-pin plastic DIP or 8-pin narrow SOIC. SP481R provides a shutdown function by enabling the pin, which can reduce the supply current (Icc) to less than 0.5uA.

(3) +3.3V low-power half-duplex RS-485 transceiver-SP3481/SP3485

features

RS-485 and RS-422 transceiver operating power supply is +3.3V

Transmitter/receiver enable for operation with +0.5V logic

Low-power shutdown mode (SP3481) -7V~+12V common-mode input voltage range

Allows connection of 32 transceivers on the same serial bus Compatible with industry standard 75176 pin configuration Transmitter output short-circuit protected

Description (SP3481, SP3485)

The SP3481 and SP3485 are members of the +3.3V low-power half-duplex transceiver family, which fully meet the requirements of the RS-485 and RS-422 serial protocols. These two devices are pin-compatible with Sipex's SP481, SP483 and SP485, and compatible with industry standard specifications.

SP3481 and SP3485 are manufactured by Sipex's unique BiCMOS process, but the performance is not affected.

(4) Enhanced low-power full-duplex RS-422 transceiver-SP490E/SP491E

features

Single +5V power supply

Low Power BiCMOS Process Manufacturing Transmitter/Receiver Enable (SP491E) RS-485 and RS-422 Transmitter/Receiver

Pin Compatible with LTC490 and SN75179 (SP490E) Pin Compatible with LTC491 and SN75180 (SP491E) Enhanced ESD Specifications:

Plus and minus 15kV human body discharge model (Human Body Model)

SP490E is a low-power differential transceiver that meets the RS-485 and RS-422 standard specifications, and the data transmission rate is up to 10Mbps. The SP491E is identical to the SP490E except for the addition of the transmitter and receiver tri-state enable lines.

Within the limits of the common mode mode, the receiver input sensitivity of both is ±200mV. SP490E includes 8-pin plastic DIP and 8-pin NSOIC packages, and can work in commercial and industrial temperature ranges.

SP491E includes 14-pin DIP and 14-pin NSOIC packages, and can also work in commercial and industrial temperature ranges.

summary

The appeal lists several commonly used chips, the pins are all compatible, but the performance is different

Points to note

(1) Common mode interference problem :

The RS-485 interface uses a differential mode to transmit signals, and it does not need to detect signals relative to a certain reference point. The system only needs to detect the potential difference between the two lines.

Long-distance wiring will cause signal attenuation, and the possibility of introducing noise and interference is greater. The performance on cables A and B is the change of voltage amplitude. However, the advantage of using differential lines is that the difference will be ignored when subtracting The ability of this differential receiver to ignore the same voltage on the two signal lines is called common-mode rejection.

In layman's terms, if there is interference during the transmission process, the voltage of the two lines A and B will change. It may be that A is 5V and B is 2V, but A is 8V and B is 5V due to interference. Since the 485 communication detects the voltage difference between the two wires, the voltage difference between A and B has not changed, it is still 3V, so the receiver still detects the correct signal

On the contrary, single-ended communication methods like serial ports and RS232, because there is only one signal line and one ground line, and a certain level state will be specified to represent a logic, such as 5V for 1, 0V for 0, when in the transmission process When interference occurs in the power supply, 5V may become 2V. At this time, it is impossible to judge whether it is 1 or 0, resulting in incorrect data transmission.

In addition, people often ignore 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 can the entire network work normally. When the common-mode voltage of 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 low-impedance return path (signal ground), it will return to the source in the form of radiation.

The entire bus will radiate electromagnetic waves outward like a huge antenna. And because the common-mode voltage range is -7V ~ +12V, so both sides of the communication also need a ground wire as a standard, and the common-mode voltage cannot exceed the range to prevent damage to the port

Due to the above reasons, although the RS-485 network adopts a differential balanced transmission method, there must be a low-impedance signal ground for the entire RS-485 network. A low-impedance signal ground connects the working grounds of the two interfaces, so that the common-mode interference voltage is short-circuited.

This signal ground can be an extra wire (unshielded twisted pair), or the shield of a shielded twisted pair. This is the most common grounding method.

(3) Terminal matching resistance

In order to match the communication impedance of the network, reduce reflection and absorb noise caused by mismatch, effectively suppress noise interference, and improve the reliability of RS-485 communication, it is necessary to install a terminal matching resistor at each of the two endpoints of the RS-485 network .

The size of the terminal matching resistance is determined by the characteristic impedance of the transmission cable. For example, the RS-485 network usually uses twisted pair or shielded twisted pair as the transmission medium, and its characteristic impedance is 120 ohms. Therefore, the two endpoints on the RS-485 bus should also be equipped with a 120 ohm terminal matching resistor. .

Matching resistors consume large currents and are not suitable for systems with strict power consumption constraints. In special occasions, the relatively power-saving parallel "RC" matching scheme can be considered, which can save most of the power, but the value of the capacitor C is a difficult point, and a compromise needs to be made between power consumption and matching quality.

Original Author: ONE_ Day|

Guess you like

Origin blog.csdn.net/youzhangjing_/article/details/132103487