Abstract This paper describes a can use RS-485 electrical characteristics and simple structure, way of serial communication using a custom protocol, RS-485 MCU multi-machine communication methods and techniques.
Key words microcontroller, RS-485 bus, bus conflicts, serial communication
RS-485 serial bus interface standard to transmit differential balanced signals, common mode has a strong anti-interference ability, allowing a pair of twisted-pair transmitter driver on a number of load equipment. Industrial control systems generally use the bus for data transmission, and generally use the RS-485 serial bus interface standard of the systems use the 8044 chip as a communication controller or the extension of the CPU. 8044 chip integrated SDLC, HDLC and other communication protocols, and integrates the hardware circuit hardware and standard protocols through the cooperation, the system of communication is accurate, reliable, fast. 8044 increasingly scarce in the market, although there are 8344 alternative, but the ordinary price several hundred dollars to tens of dollars on single chip a few dollars a far cry from the price, the user general microcomputer application in the development system, using simple, all hope circuit and a simple communication protocol for data exchange. For example: the use of single chip itself provides a simple serial interface, coupled with the bus drivers and other combinations such as the SN75176 into a simple RS-485 communications network. The method described in this article have been successfully used in engineering projects, a host with 60 slave communication, communication baud rate 64KBPS.
2 bus driver chip SN75176
Common RS-485 bus driver chips have SN75174, SN75175, SN75176. SN75176 chip has a transmitter and a receiver is very suitable for RS-485 bus driver chips.
SN75176 and the logic shown in Figure 1.
Figure 1 SN75176 chip and its logic
3 RS-485 communication method to form the principle of multi-machine
Constituted by the single chip multi-serial communication system, the general master-slave structure: from the machine does not take the initiative to send commands or data, all controlled by the host. And in a multi-machine communication system, only a single as the host, between the various units from the machine can not communicate with each other, even if there is exchange of information must be forwarded by the host. RS-485 form with the multi-machine communication block diagram shown in Figure 2.
Figure 2 is composed of RS-485 block diagram of multi-machine communication
Then a match in the bus terminal resistor to absorb the reflected signal on the bus, the normal transmission of signals to ensure a clean, burr-free. Resistor value should match the characteristic impedance of the bus quite.
When there is no signal transmission on the bus, the bus is in suspended state, vulnerable to interference signals. The bus differential signal positive terminal of the A + and +5 power indirectly, a 10K resistor; positive side A + and negative B-indirectly, a 10K resistor; negative side of the B-and indirectly, a 10K resistor to form a resistor network. When there is no signal transmission on the bus, the positive side A + level is about 3.2V, the negative terminal B-level is about 1.6V, even with interference signals, it is difficult to start a serial communication signal 0 to increase the capacity of the bus interference.
4 traffic rules
Since RS-485 half-duplex communication is a communication, send and receive share the same physical channel. At any time only one single in the sending state. Therefore, the single required response must listen to the call signal has been sent on the bus is completed, and no other single case of an acknowledge signal to response. Half-duplex communication on the master and slave transmit and receive timing, there are strict requirements. If the timing with the bad, bus collision occurs, the whole system of communication paralyzed and unable to work. To achieve the timing device on the bus with the strict, we must follow the following principles:
1) reset, the master and slave should be in the receiving state.
SN75176 chip transmit and receive function of conversion is a chip RE *, DE-side control. RE *= 1, DE = 1 ?, SN75176 sending state; RE *= 0, DE = 0 ?, SN75176 in the receiving state. General use of a microcontroller port cable RE *, DE side. During reset, due to the hardware and stability will take some time, and the microcontroller is high after reset the port state, which would make the extension is sent on the bus each state, plus the circuit when the power is unstable, may send information to the bus. Therefore, if the line with a port for sending and receiving control signals, should be the reverse port line of control after the end of access SN75176, SN75176 on power in the receiving state.
In addition, the software on the master and slave should also add a number of treatment measures, such as: the power or formal communication before the air several times on the serial port operation, clear the port of illegal data and commands.
2) control terminal RE *, DE signal should be greater than the effective pulse width to send or receive a signal width.
In the RS-232, RS-422 and other full-duplex communication process, transmit and receive signals at different physical transmission link, the sender is always the sender, the receiver is always the receiving end, there is no send, receive control signals switching problem. In the RS-485 half-duplex communication, the sending and receiving of SN75176 by the same device to complete, and send and receive using the same physical link must be switched on the control signal. When the control signal is high, when low, generally of a microcontroller TI, RI signal for reference.
Sent to detect whether the established TI, TI is high when the sending off changed after receiving function;
Received, the detection of RI is set up, when the RI is high, the receiving end, they can turn to send.
Although the works in theory, but in practice the FBI to transfer data have emerged during the time of the wrong phenomenon. According to verify the information, and the FBI in the storage oscilloscope with repeated testing, only to find a noteworthy problem, we can see the microcontroller timing:
Figure 3 Serial Port Mode 3 timing diagram
Microcontroller serial port to send data, as long as 8 data bits transmission is completed, TI flag is set up, but at this time should send the ninth data bit (if the sender address frame) and the stop bit has not been issued. If this is sent off control, will inevitably result in incomplete data transmission frame. If the MCU multi-machine communication using the higher baud rate, delay of several operating instructions may be more than 2 (or 1) data transmission time, the problem may not arise. But if a lower baud rate, such as 9600, sending a data to be 100µs or so, several operating instructions of the delay alone is not enough, the problem is clearly exposed. The same is true when receiving data, the microcontroller at the receiving end after 8 data bits to build RI signal, but at this time has not yet received the ninth data bit (if received address frame), and stop bits. Therefore, the receiver must delay of more than two data bits of the time (one data bit time = 1 / baud rate), and then make answer, or bus collision occurs.
3) connected to the bus send control signals of the single completely separated in the timing.
Send and receive signals in order to ensure the integrity and the right to avoid the collision signal on the bus, the right to use the bus must be assigned to avoid competition, connected to the bus stand-alone, and send control signals to be completely isolated in time.
In short, send and receive control signals should be wide enough to ensure the integrity of the data to receive one, any two stand-alone transmission control signals are completely separated in time to avoid bus dispute.
Process flow diagram, see Figure 4. Of which: a) to send flow; b) to receive the flow chart.
Program flow chart in Figure 4
Note: The delay value of T seconds
(1) to send the address frame, T> 2X (1 / baud rate), you can select T = 2.5X (1 / baud rate).
(2) to send the data frame, T> 1X (1 / baud rate), you can select T = 1.5X (1 / baud rate).
About the Author: Yin Hong engineer. Mainly engaged in computer applications and numerical product research and development
Tang Yu researchers. Computer Automation Conference is mainly engaged in product research and development work
Author: Institute of Sichuan, Chengdu Institute of Computer Application. Chengdu (610041)