Reliability Measures of RS-485 Bus Communication System

Publisher:CoboroLatest update time:2006-05-16 Source: 单片机及嵌入式系统应用Keywords:RS-485  data  node Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
   1 Question raising

  One of the more commonly used networks in the field of industrial control and measurement is the industrial control equipment network composed of the RS-485 communication interface at the physical layer. This communication interface can easily combine many devices into a control network. Judging from the analysis of many current solutions to medium and long-distance communication between microcontrollers, the RS-485 bus communication mode is widely used in instrumentation, intelligent equipment, etc. due to its simple structure, low price, appropriate communication distance and data transmission rate. Sensor distributed control, building control, monitoring and alarm and other fields. However, the RS485 bus has shortcomings such as adaptive and fragile self-protection functions. If you do not pay attention to some details, communication failures or even system paralysis often occur. Therefore, it is crucial to improve the operational reliability of the RS-485 bus.

 
                Figure 1 RS485 communication interface schematic diagram

  2 Issues that need attention in hardware circuit design

  2.1 Basic principles of circuit

  The hardware circuit design of a certain node is shown in Figure 1. In this circuit, an RS-485 interface chip SN75LBC184 is used, which uses a single power supply Vcc and can work normally in the range of +3 to +5.5 V. Compared with ordinary RS-485 chips, it can not only withstand lightning strikes but also withstand electrostatic discharge shocks up to 8 kV. It integrates four instantaneous overvoltage protection tubes on the chip and can withstand transient pulse voltages up to 400 V. Therefore, it can significantly improve the reliability of devices that prevent lightning damage. For some sites with relatively harsh environments, it can be directly connected to the transmission line without any additional protection components. The chip also has a unique design. When the input end is open circuit, its output is high level. This ensures that when the receiver input end cable has an open circuit fault, it does not affect the normal operation of the system. In addition, its input impedance is twice the standard input impedance of RS485 (≥24 kΩ), so 64 transceivers can be connected to the bus. A limited slope drive is designed inside the chip so that the edge of the output signal will not be too steep and excessive high-frequency components will not be generated on the transmission line, thus effectively suppressing electromagnetic interference. In Figure 1, the four-in-one optocoupler TLP521 completely eliminates the electrical connection between the microcontroller and SN75LBC184, improving the reliability of the work. The basic principle is: when the microcontroller P1.6=0, the light-emitting diode of the optocoupler emits light, the phototransistor is turned on, and outputs high voltage (+5 V). The DE end of the RS485 interface chip is selected to allow transmission . When the microcontroller P1.6=1, the light-emitting diode of the optocoupler does not emit light, the phototransistor does not conduct, and outputs low voltage (0 V). Select the RE end of the RS485 interface chip to allow reception. The principles of the R end (receiving end) and D end (transmitting end) of SN75LBC184 are similar to the above.

  2.2 DE control terminal design of RS-485

  In the half-duplex communication system built on the RS-485 bus, only one node in the entire network can be in the sending state and send data to the bus at any time, and all other nodes must be in the receiving state. If there are 2 nodes or more than 2 nodes sending data to the bus at the same time, it will cause the data sending of all senders to fail. Therefore, in the hardware design of each node in the system, we should first strive to avoid bus data conflicts caused by abnormal situations causing the node to send data to the bus. Take the MCS51 series of microcontrollers as an example. When the system is reset, the I/O ports output a high level. If the I/O ports are directly connected to the driver enable terminal DE of the RS-485 interface chip, the CPU will reset. During this period, DE is high, thereby placing this node in the sending state. If there are other nodes on the bus sending data at this time, the data transmission will be interrupted and fail, or even cause the entire bus to be blocked due to the failure of a certain node, thus affecting the normal operation of the entire system. Considering the stability and reliability of communication, in the design of each node, the sending pin that controls the RS485 bus interface chip should be designed as the inverse logic of the DE end, that is, when the control pin is logic "1", the DE end is " 0"; when the control pin is logic "0", the DE terminal is "1". In Figure 1, the CPU pin P1.6 drives the DE terminal through the optocoupler, so that the SN75LBC184 is always in the receiving state when the control pin is high or abnormally reset, thereby effectively preventing the node from being abnormal in hardware. impact on the entire system. This lays the foundation for reliable communication of the entire system.

  In addition, there is a watchdog MAX813L in the circuit, which can automatically reset the program and hand over control of the RS-485 bus when an infinite loop or other failure occurs at the node. This ensures that the entire system will not monopolize the bus due to a node failure, causing the entire system to be paralyzed.

  2.3 Design to avoid bus conflicts

  When a node needs to use the bus, in order to achieve reliable bus communication, it first listens to the bus when there is data to be sent. On the hardware interface, first invert the data receiving pin of the RS-485 interface chip and then connect it to the interrupt pin INT0 of the CPU. In Figure 1, INT0 is connected to the output of the optocoupler. When data is being transmitted on the bus, the data receiving end (R end) of SN75LBC184 shows changing high and low levels. Using the CPU falling edge interrupt generated by it (query mode can also be used), you can know whether the bus is normal at this time. "Busy" means whether there are nodes on the bus communicating. If "idle", you can get the permission to use the bus, which better solves the problem of bus conflict. On this basis, the priorities of various messages can also be defined so that high-priority messages can be sent first, thereby further improving the real-time performance of the system. After adopting this working method, there is no distinction between master and slave nodes in the system, and each node has equal access to the bus, thus effectively avoiding the heavy communication burden on individual nodes. The utilization of the bus and the communication efficiency of the system are greatly improved, which also improves the real-time response of the system. Even if an individual node in the system fails, it will not affect the normal communication and normal work of other nodes. In this way, the "danger" of the system is dispersed, and to a certain extent, the working reliability and stability of the system are enhanced.

  2.4 Design of the RS-485 output circuit part

  
In Figure 1, VD1 ~ VD4 are signal limiting diodes, and their voltage stabilization values ​​should ensure that they comply with the RS-485 standard. VD1 and VD3 take 12 V, VD2 and VD4 take 7 V, so Ensure that the signal amplitude is limited to -7 ~ +12 V to further improve the ability to withstand overvoltage. Taking into account the special circumstances of the line (such as the RS-485 chip of a certain node being broken down and short-circuited), in order to prevent the communication of other extensions in the bus from being affected, two 20 Ω resistors R1 and R2 are connected in series at the signal output end of SN75LBC184 , so that the hardware failure of the local machine will not affect the communication of the entire bus. In the on-site construction of application system engineering, since the communication carrier is a twisted pair, its characteristic impedance is about 120 Ω. Therefore, when designing the line, a 120 Ω matching resistor should be connected at the beginning and end of the RS485 network transmission line ( Such as R3 in Figure 1) to reduce the reflection of the signal transmitted on the line.

  2.5 System power supply selection

  For a measurement and control network composed of a microcontroller combined with RS-485, priority should be given to the solution of independent power supply for each node. At the same time, the power line cannot share the same multi-core cable with the RS-485 signal line. RS-485 signal lines should use twisted pairs with a cross-sectional area of ​​0.75 mm2 or more instead of straight lines, and linear power supply TL750L05 is more suitable than switching power supply. TL750L05 must have an output capacitor. If there is no output capacitor, the voltage at the output terminal will be in the shape of a sawtooth wave. The rising edge of the sawtooth wave changes with the input voltage. Adding an output capacitor can suppress this phenomenon.

  3 Software programming

  When SN75LBC184 is in receiving mode, A and B are inputs and R is output; in sending mode, D is input and A and B are outputs. When the transmission direction changes once, if the input does not change, the output will be in a random state at this time. The output state will not be determined until the input state changes once. Obviously, after switching from the sending mode to the receiving mode, if R is low level before the status of A and B changes, and R is still low level at the first data start bit, the CPU thinks that there is no start at this time. bit, the CPU does not start receiving the first data until the first falling edge occurs, which will cause a receive error. After switching from receiving mode to sending mode, before D changes, if the voltage between A and B is low, when the first data start bit is sent, the voltage between A and B is still low, and the A and B pins have no start. starting position will also cause sending errors. The solution to overcome this consequence is: the host sends two synchronization words continuously, the synchronization words should contain multiple edge changes (such as 55H, 0AAH), and send them twice (the first time may be received incorrectly and ignored), and the receiving end receives After the synchronization word, data can be transmitted to ensure correct communication.

  In order to work more reliably, an appropriate delay is required when the RS485 bus status is switched before sending and receiving data. The specific method is to set the control terminal to "1" in the data sending state, delay for about 0.5 ms, and then send valid data. After the data transmission is completed, delay again for 0.5 ms and set the control terminal to "0". ". Such processing will allow the bus to have a stable working process when switching states. The basic flow chart of the data communication program is shown in Figure 2.

            
            
  Figure 2 Basic flow chart of data communication program

  The program of the microcontroller communication node can basically be divided into 6 main parts, namely the predefined part, the initialization part, the main program part, the device status detection part, the frame receiving part and the frame sending part. The predefined part mainly defines the handshake signals used in communication, the buffer used to save device information and the variables that save the device number of this node. The equipment status detection part should be able to respond accordingly when the hardware fails after the program is initialized. The main program part should be able to receive the command frame and respond accordingly according to the content of the command. To shorten the length, only the code of the main program part is given here. As follows:

  /* Main program flow*/
  while(1) { //Main loop
    if(recv_cmd(&type)==0) //A frame error occurs or the frame address does not match the local
                // address, discard the current frame and return
  to continue;
  switch (type) {
    case __ACTIVE_: //The host asks the slave whether there is
      send_data(__OK_, 0,dbuf); //Send response information
      break;
    case __GETDATA_:
      len = strlen(dbuf);
      send_data(__STATUS_, len,dbuf); //Send status information
        break;
    default:
        break; //Wrong command type, discard the current frame and return
    }
  }

  4 Conclusion

  Because RS-485 uses differential level transmission signals, the transmission distance is longer than RS-232, up to 3000 m, so it is very suitable for applications in industrial environments. However, compared with more advanced field industrial buses such as CAN bus, its ability to handle errors is still slightly inferior, so special design is required in the software part to avoid data errors and other situations. In addition, the system has a large amount of data redundancy, and the RS-485 bus is not suitable for applications with high speed requirements. Although the RS-485 bus has some shortcomings, due to its simple circuit design, low price, and convenient control, as long as the details are handled well, it can still play a good role in some engineering applications. In short, the key to solving the problem of reliability is to consider all the measures that can be taken before the construction of the project begins, so that the problem can be fundamentally solved instead of waiting until the later stages of the project to make up for it.

  references

1 Qiushi Technology. Single-chip microcomputer communication technology and engineering practice. Beijing: People's Posts and Telecommunications Press, 2005
2 Shen Hongxing. A network protocol based on RS485 bus and its implementation method. Single-chip microcomputer and embedded system applications, 2003(6)
3 Wu Jun Hui. Research on RS485 bus communication obstacle avoidance and multi-master transmission. Measurement and Control Technology, 2002(8)
4 Liu Guangbin. Anti-interference technology of single-chip microcomputer system. Beijing: People's Posts and Telecommunications Press, 2003

Keywords:RS-485  data  node Reference address:Reliability Measures of RS-485 Bus Communication System

Previous article:Microcontroller and PC telephone remote communication system
Next article:Implementation of dual-machine communication on CPCI bus

Recommended ReadingLatest update time:2024-11-16 16:20

Change MYS_SAM9X5 to dataflash boot
Because the nand scrub command was used carelessly before and caused the nandflash to be unusable, I considered changing the MYS_SAM9X5 development board to dataflash startup. Before making any changes, you must first clarify the relationship between bootstrap and u-boot: The at91 architecture u-boot is not like o
[Microcontroller]
Detailed explanation of three classic RS-485 port EMC protection solutions
In actual industrial, power, automation and instrumentation applications, the RS-485 bus standard is one of the most widely used physical layer bus design standards. Since it will work in a harsh electromagnetic environment, in order to ensure that these data ports can work properly in the final installation environme
[Power Management]
Detailed explanation of three classic RS-485 port EMC protection solutions
Latest Industrial Control Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号