“RS485 belongs to a half-duplex bus. In actual use, the host polling or token passing method is generally used to allocate bus control rights. The RS485 device needs to convert the direction of sending and receiving. A common practice is that each RS485 device is in the receiving state at ordinary times, and only switches to the sending state when it has data to send, and switches back to the receiving state after the data is sent.
Author: Da Nianjun
1. Features of RS485 communication interface
As a commonly used communication method in the industrial field, the RS485 bus has the following characteristics:
(1) The level between the transceiver outputs A and B is +2V~+6V, which is a logic “1”; it is -6V~-2V, which is a logic “0”. The signal level is lower than that of RS232, and it is not easy to damage the interface chip. There is also an “enable” control signal that puts the transceiver in a high-impedance state, cutting off the connection to the transmission line.
(2) The input sensitivity of the receiver is 200mV. That is, the logic can be output when the level difference between the receiving ends A and B is 200mV.
(3) The transmission rate is high (10Mbps), and the transmission distance reaches 1200m.
(4) It has multi-site transmission capability, that is, up to 128 transceivers are allowed to be attached to the bus, and a device network can be established.
(5) The common mode voltage range of the RS485 transceiver is -7V to +12V. Only when this condition is met, the entire network can work normally. When the common mode voltage of the network line exceeds this range, it will affect the stability of communication and even damage the interface.
2. RS485 transceiver control method
RS485 belongs to a half-duplex bus. In actual use, the host polling or token passing method is generally used to allocate bus control rights. The RS485 device needs to convert the direction of sending and receiving. A common practice is that each RS485 device is in the receiving state at ordinary times, and only switches to the sending state when it has data to send, and switches back to the receiving state after the data is sent.
1. The first type: program commutation control
The most commonly used RS485 transceiver commutation method is program commutation, that is, an I/O port of the MCU controls the transceiver enable pin of the RS485 transceiver device, and the RS485 transceiver device is usually in the receiving state, as shown in the figure below, where the 485 chip is used. TI’s SN65LBC184 has a maximum rate of 250Kbps. When there is data to be sent, the MCU puts the RS485 transceiver device pin (network RS485_EN2) into the sending state. After the data transmission is completed, the RS485 transceiver device is switched back to the receiving state.
This method is simple and easy to implement without adding extra cost. This method is known to many people and basically used.
2. The second type: automatic commutation
However, when we use an industrial control motherboard or core board of a certain hardware platform for secondary development, because there are not enough I/O ports reserved on the industrial control motherboard or core board, the program commutation method of RS485 transceiver cannot be realized. In some specific cases, the underlying driver of the development platform is not open to the outside world, and it is difficult to carry out secondary development of the underlying layer. In this case, even if there are enough I/O ports, program reversal cannot be realized. To this end, we need to adopt another commutation technology, that is, automatic commutation technology. In fact, automatic commutation does not require a separate I/O port to control the enable pin, but is controlled by the way when the send pin sends data.
To achieve this method, an inverter can be added there, as shown in the figure below, in the idle state, the transmission signal TXD2 of the serial port is a high level, and after passing through the inverter, it outputs a low level, so that the SN65LBC184 is in the receiving state, and The RS485 bus is in the state of A high and B low due to the action of the pull-up and pull-down resistors. When sending data, the low-level bit on the TXD2 signal line controls the SN65LBC184 to enter the sending state, and the bit is sent out. The high-level bit makes the SN65LBC184 in the receiving state, and the pull-down resistor on the RS485 bus puts the bus in the state of A high and B low, which means that a high level is sent.
The inverter can also be replaced by a triode, as shown in the figure below, and the working principle is the same as adding an inverter.
However, this method has limited driving ability when sending a high level, so it will limit the communication distance, and is generally suitable for occasions with a short distance.
In fact, in order to save the trouble of control, you can also use a special 485 chip with AutoDirecTIon function, such as MAX13487E, which saves the commonly used 485 enable signal, thereby simplifying the design circuit.