Share this

Design of an intelligent data acquisition network instrument based on RS-485 protocol

2026-04-06 08:00:37 · · #1
Abstract: This paper introduces the RS-485 communication protocol and an RS485 interface chip, MAX485, and discusses in detail how to use this chip and the RS-485 protocol to facilitate multi-point communication between a computer and a PHILIPS P89C51RD2 microcontroller. Keywords: Communication protocol, microcontroller, computer, multi-point communication I. Introduction In many data acquisition systems such as instruments and intelligent devices based on microcontrollers, it is often necessary to realize data exchange between a computer and a microcontroller, which is communication between the microcontroller and the computer. This allows for full utilization of the strengths of both the microcontroller and the computer, improving the performance and cost-effectiveness of the entire application system. Traditional RS-232-based communication suffers from limitations such as short transmission distance, slow speed, and susceptibility to signal interference, making its application increasingly limited. Therefore, this paper discusses how to construct an RS-485 communication network based on the RS-485 communication protocol to achieve remote communication between several microcontrollers and a computer. II. Hardware Design 1. Introduction to RS-485 Communication RS-485 is a balanced transmit/receive standard asynchronous serial bus defined by the EIA (Electronic Industries Association). It has advantages such as long transmission distance, high sensitivity, and strong multi-point communication capability. See Table 1 for the RS-485 interface standard. 2. Introduction to the MAX485 Chip The RS-485 conversion interface chip we use is the MAX485 from MAXIM (see Figure 1). This chip operates on a single +5V power supply, with a rated current of 300uA, and uses half-duplex communication. It converts TTL levels to RS-485 levels. This chip has 8 pins, internally containing two drivers and a receiver. RO and DI are the output of the receiver and the input of the driver, respectively, connected to the microcontroller's TXD and RXD. /RE and DE are the receive and transmit enable pins, respectively. When /RE=0, the MAX485 is in receive mode; when DE=1, the MAX485 is in transmit mode. Because the MAX485 operates in half-duplex mode, its connection to a microcontroller is very simple; only one pin on the microcontroller is needed to control these two pins. Pins A and B are the differential signal terminals for receiving and transmitting, respectively. When VA is greater than VB, it indicates that the transmitted data is "1"; when VA is less than VB, it indicates that the transmitted data is "0". A matching resistor should be added between A and B during operation; a 100-120 ohm resistor is generally suitable. Level conversion is necessary when the PHILIPS P89C51RD2 microcontroller communicates with a computer. Since the communication between the microcontroller and the computer is via an RS-485 network, the signal from the microcontroller is converted from TTL level to RS-485 level after passing through the MAX485. Therefore, the RS-485 signal must be converted back to RS-232 level on the computer side for correct communication. This system uses a DAC-8520 converter to convert RS485 signals to RS-232 signals. This converter offers fast data conversion and transmission speeds and requires no user initialization or parameter modification. Table 1 shows the RS-485 interface standard. 4. Computer-side interface: The computer uses a programmable serial asynchronous communication controller 8251A. Initializing the 8251A allows control over the serial data transmission format, speed, and operating mode, ensuring consistency with the microcontroller's communication method, thus enabling communication between the computer and the microcontroller. III. Multi-point communication 3.1 Multi-point communication principle: The RS485 bus standard is developed based on RS-422, adding multi-point bidirectional communication capabilities, enabling multi-point communication in distributed networks. After understanding the device's driving capabilities, we can add the necessary nodes based on requirements and driving capabilities. This system utilizes one computer to control up to 32 microcontrollers. The computer establishes communication connections with the required microcontrollers by sending control words and operating mode words. The microcontroller acquires data according to instructions sent by the computer and exchanges data with the computer as needed, or adjusts production process parameters and the status of connected equipment. After analyzing and calculating the data returned by the microcontroller, the computer transmits the relevant control information back to the microcontroller. When using the 51 series microcontroller for multi-point communication, it must operate in mode 2 or mode 3. Taking mode 3 as an example, each frame of data sent is 11 bits: 1 start bit (0), 8 data bits, and 1 stop bit (1). The additional 9th ​​data bit is the parity bit in non-multi-point communication systems, generated by SCON TB8 at the sending end and transmitted to RB8 at the receiving end. It can also be set to "0" or "1" as a flag to distinguish between data frames (0 flag) and address frames (1 flag) in multi-point communication. In a 51 series microcontroller multipoint communication system, the following communication protocol applies: All slave devices are in a ready state (SM2=1) to receive addresses from the master. When RB8 of a received frame is "1", it indicates that the master has sent address information, and all slave devices trigger a receive interrupt; otherwise, the interrupt is masked. When a slave device enters its corresponding interrupt service routine, it compares the received address with its own address. If they match, it sets SM2 to 0 and sends its own address back to the master as a response. This slave device then connects to the master and prepares to receive commands or data from the master. Other unaddressed slave devices maintain SM2=1 and exit their respective interrupt service routines. In this way, only slave devices with SM2=0 can receive data from the master, successfully separating address frames and data frames. Addressed slave devices reset SM2=1 after communication is complete and exit their interrupt service routines, waiting for the next communication. 3.2 Multipoint Communication Protocol To achieve normal communication between a computer and a microcontroller, their operating modes must be correctly configured to ensure that both use the same baud rate, start bit, stop bit, and parity bit, and that acknowledgment signals are established for communication between the two. The microcontroller can operate in either synchronous shift register mode or UART (Universal Asynchronous Receiver/Transmitter). The serial port communication mode is controlled by the special function register SCON. Its bits are defined as follows: SM0, SM1: Operating mode setting bits; SM2: Enables multi-machine communication control bits for modes 2 and 3; RB8: 9th bit of received data; TB8: 9th bit of transmitted data; TI: Transmit interrupt flag; RI: Receive interrupt flag. In this paper, the operating mode is Mode 3, where the 9-bit UART timer T1 acts as a baud rate generator, operating in Mode 2. If the selected baud rate is 9600bps, the initial count value is 0FAH (SMOD=0, clock frequency Fosc is 11.0592MHz). The computer's asynchronous communication interface is the Intel 8251A, which can be set with 1, 1.5, or 2 stop bits, and the data can be selected between 5 and 8 bits. The communication frequency is 0 to 9600bps, and it has three modes: parity check, frame check, and overflow check. It can be initialized by writing certain mode control words and command control words. Its operating status is registered in the status register, which can be read by the CPU of the P89C51RD2. The communication protocol is as follows: (1) The serial communication baud rate is 9600bps; (2) The frame format is 8 data bits, one start bit, one programmable 9th bit (i.e., the address/data bit flag for sending and receiving), and one stop bit; (3) The master and slave follow the master-slave principle. The master selects the slave by calling. Data is transmitted bidirectionally between the master and the slave. Communication between slaves needs to be mediated by the master; (4) The master and slave should also transmit some commands and status words for their identification, such as 00H indicating that the master sends a command to the slave to receive, and 01H indicating that the slave sends a command to the master to receive, etc. IV. Software Design This part mainly consists of the master program, the slave program, and its interrupt service program. The master program mainly completes the serial port initialization and the communication between the master and the slave. The slave master program mainly completes the serial port initialization and baud rate setting (which should be consistent with the baud rate of the master). Its interrupt program mainly completes the data communication between P89C51RD2 and the computer. 1. The microcontroller-side program was written in C language within the excellent visual integrated development environment uVISION2 provided by KEIL. The communication baud rate is 9600bps, and the crystal oscillator is 11.0592MHz. It is important to note that one machine cycle of the PHILIPS P89C51RD2 is 6 clock cycles, which differs from the standard 8051 microcontroller's 12 clock cycles. Therefore, this difference must be considered when setting relevant parameters; otherwise, a correct communication connection cannot be established. To facilitate multi-machine communication, we adopted working mode 3. The microcontroller communication flowchart is shown in Figure 2. The microcontroller serial port initialization program is as follows: main() { TMOD = 0x20; /* Timer 1 Mode 2 */ TH1=0xfa; /* 9600 baud rate crystal oscillator 11.0592MHz */ TCON=0x40; /* Start Timer 1 */ SCON=0x50; /* Enable reception */ IE=0x90; /* Enable serial port interrupt */ ……….. 2. Computer Part The computer-side program is written using the excellent visual software Visual Basic. The key part is the use of the Visual Basic serial communication control MSComm. Sending and receiving are completely managed by this control, eliminating the need for the previously cumbersome driver programming. This undoubtedly greatly improves work efficiency and reduces development costs. The computer communication process is shown in Figure 3. The following is a communication program written in VB6: Dim inbyte() AS Byte 'Define a dynamic byte array Private Sub txd_click() 'Communication establishment and data transmission control button If MSComm1.PortOpen = True Then GoTo jj If the communication port is open, jump to jj MSComm1.CommPort = 1 'Communication port is COM1 MSComm1.Settings = "9600,n,8,1" 'Initialize the serial port to 9600 baud, 8 data bits, 1 stop bit, no parity MSComm1.PortOpen = True 'Open the communication port jj: Mscomm1.output=Text1.text 'Send address code……….. Mscomm1.output=text2.text 'Send working mode control word, acquisition channel and checksum End Sub Private Sub rxd_click() 'Data reception button Inbyte() = Mscomm1.input 'Received data is stored in a dynamic byte array……. 'Omitted data processing part End Subsection 5: Conclusion Utilizing RS-485 serial communication ensures fast, stable, and long-distance data transmission. The system designed in this paper has been successfully applied in intelligent data acquisition network instruments, and its communication design method can be easily modified and ported to other industrial measurement and control systems. Due to its low development cost and simple design, the method presented in this paper will undoubtedly find increasing application in current and future industrial control and other fields.
Read next

CATDOLL 133CM Sasha Shota Doll

Height: 133cm Male Weight: 28kg Shoulder Width: 31cm Bust/Waist/Hip: 64/59/73cm Oral Depth: 3-5cm Vaginal Depth: N/A An...

Articles 2026-02-22
CATDOLL Airi TPE Head

CATDOLL Airi TPE Head

Articles
2026-02-22
CATDOLL Ava Soft Silicone Head

CATDOLL Ava Soft Silicone Head

Articles
2026-02-22
CATDOLL 146CM Laura TPE

CATDOLL 146CM Laura TPE

Articles
2026-02-22