Serial communication between industrial computer and single-chip master-slave distributed control system

Jan 05, 2022

Eine Nachricht hinterlassen

Hardware Interface Design The control system described in this paper is composed of industrial computer and multiple AT89C2051 single-chip computers. Data transmission between master and slave uses asynchronous serial communication. Since the serial communication port of the industrial computer is an RS-232C interface, its logic level is symmetrical to the ground, which is different from the TTL level output by the serial port of the AT89C2051 single-chip microcomputer. Therefore, it is necessary to ensure reliable data transmission between the two. A level converter should be connected to the communication line. Common level converter chips include ICL232 and MAX232 chips. This text uses the MAX232 level conversion chip.

Multiple single{{0}}chip computer communication circuit 2 software design 2.1 AT89C2051 single-chip computer multi-computer communication function AT89C2051 single-chip microcomputer serial port has: serial send buffer/receive buffer (SBUF), serial port control register (SCON), special function register ( PCON). There are 4 working modes by setting SCON, among which working modes 2 and 3 are suitable for multi-computer communication. The serial communication mode 3 of the AT89C2051 single-chip microcomputer is a 9-bit data asynchronous communication mode with a variable baud rate, and is also the most widely used mode in multi-computer communication at present. Here, AT89C2051 transmits a frame of information with 11 bits in total: 1 start bit, 8 data bits, 1 bit can be programmed to be the 9th bit of "1" or "0" and 1 stop bit, among which The ninth bit of data can be used as a parity bit, and can also be used as an identification flag for "address frame" and "data frame".

Industrial computer communication function The industrial computer is equipped with a serial asynchronous communication port (COM1 port address is 3f8H, CM2 port address is 2f8H), and the universal asynchronous receiver/transmitter (UART) on the interface board is a piece of 8250 or a piece of structure, programming method Same chip as 8250 with 10 registers inside. PC serial communication programming, programmers only need to use input/output commands to input/output the registers in the UART, so as to set the serial communication baud rate, data transmission format, whether to allow interrupts, send or receive data Wait.

A new multi-machine communication method In the conventional multi-machine communication method, the parity bit has been used as the characteristic bit of the sending address code (channel number) or data, and the check of the data communication adopts the accumulation and check method. Using this method not only increases the software overhead and the amount of data for communication, but also affects the real-time performance. 2.3.1 Basic Principles of Communication

The data is 5 2 - set to "0" directly, and make plus , clear, then no matter what the value of the ninth bit data ( plus 9 8) is, the lower computer can generate serial reception interrupt, so the ninth bit can be used as Error detection parity bit too. For example, when the upper computer communicates with a lower computer, the address code is sent first, and then the data command is sent after the handshake is successful. At this time, the FLAG of the lower computer is set to "1", which is equivalent to the "pocket" of the machine has been opened. The computer continuously fetches data from the lower-position computer, and issues a command to restore the FLAG in the lower-position computer to "0" after fetching without error to realize "closing the pocket".

When the lower computer sends data to the upper computer, it first sends the length of the data to be transmitted, and then starts to send valid data.

It is agreed that {{0}}H is the fetch command, 0FFH is the reset command, the communication adopts even parity, and the baud rate is set to 2400b/s. The flow chart of the main function of the PC is given above, as shown. The PC communication program is written in VC plus plus 6.0 language. The communication module of the lower single-chip microcomputer includes the main program and the interrupt service program, and its program flow chart is shown in and respectively. How to realize the one-to-one communication between the upper computer and the lower computer with the corresponding sending address? Software method can be used. The specific method is as follows: a flag variable FLAG is set up in the lower computer program, and FLAG is set to "0" during initialization. When the upper computer sends data, each lower computer will generate a receiving interrupt, and the interrupt service routine first judges the value of the local FLAG. . If FLAG is "0", compare the received data with the local address, if it is consistent, set FLAG to 6", and send back the local address code as a response, otherwise jump out of the interrupt service routine immediately; if FLAG is "1" , indicating that the control command sent by the upper computer is transferred to the corresponding command processing program, and finally jumps out of the interrupt service routine and returns to the main program. After the communication between the upper computer and the lower computer is completed, the FLAG of the lower computer is set to "0" .If the handshake fails, the upper computer sends a reset command to the lower computer, and then starts the handshake again, if it fails three times, it will turn to error processing.

Implementation method and reliability measures of industrial computer software ①Number each lower computer and use it as the address code of the computer.

Conclusion This article only outlines one method of serial interface of distributed control system, but there are many communication interface methods between each machine, such as: direct connection of serial port (when the distance is short), connection through modem, etc. In terms of software programming, the slave machine is directly written in the assembly language of the single-chip microcomputer; and the communication subroutine module of the industrial computer can also be implemented in a variety of languages. Therefore, in the specific system design, one of the methods can be selected according to the actual situation, and the error detection and error correction technology can be considered in the programming, and reliable communication can be completed.

Anfrage senden