Multi-machine parallel communication system based on 89S51 single chip microcomputer

Publisher:SecretWhisperLatest update time:2010-11-19 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

In some complex systems, there are data transmission problems between systems and subsystems, subsystems and devices, etc., which are often solved by communication. Due to the different communication baud rates of subsystems and devices, especially the existence of some special baud rate devices, it is difficult to achieve mutual communication between devices in the system. For example, in a system, the host computer receives data from a certain device, as shown in Figure 1, device 1 and device 2 use a baud rate of 172.8 kbps, and the host computer is programmed with VB, and its communication baud rate is 115.2 kbps, 128 kbps or 256 kbps, etc., so the devices cannot communicate with each other, which brings difficulties to the design. In order to solve the above problems, a dual-chip microcomputer circuit is used to design a baud rate converter, which converts the received baud rate of 172.8 kbps into an output baud rate of 115.2 kbps, thereby making communication between devices with different baud rates possible.

1 Baud rate conversion circuit

The baud rate conversion circuit is shown in Figure 2. The circuit uses two single-chip microcomputers 89C51 as the core of the circuit, and uses the UART serial port of the single-chip microcomputer to communicate with related devices. The single-chip microcomputer u1_L. (connected to a device with a low baud rate) communicates with a device with a baud rate of 115.2 kbps, and the single-chip microcomputer U2_H (connected to a device with a high baud rate) communicates with a device with a baud rate of 172.8 kbps. U1_I and U2_H communicate in parallel port mode to speed up the data transfer rate between U1_I and U2_H. The communication between U1_L and U2_H can be carried out in the form of interrupt query or handshake query.

The circuit uses two 75176 interface driver chips to form an RS-422 communication interface. The communication interface composed of U3 and U4 is connected to the 115.2 kbps device, and the communication interface composed of U5 and U6 is connected to the 172.8 kbps device. The communication interface uses interrupt technology. The working principle of the baud rate converter is as follows: After U1_I. receives the data from the device from the serial port, it outputs the data from the PI port and notifies U2_H to fetch the data. After U2_H fetches the data, it sends the data to the device and notifies U1_I. that the data has been taken away, preparing for the next data output by U1_L. When U2_H receives data from the device through the serial port, it queries U1_I to see if it is allowed to receive data. If it is allowed to receive data, U2_H outputs data from P1 port and notifies Ul_L to fetch data. After Ul_L fetches data, it sends data to the device and notifies U2_H that it has taken data to prepare for the next data output by U2_H. If Ul_L does not allow data to be received, U2_H will temporarily suspend sending data.

2 Application of baud rate converter

In applications, baud rate converters can be divided into unidirectional transmission and bidirectional transmission according to the usage. Data transmission between two microcontrollers can be done in interrupt mode or query mode. If query mode is used, several bits of P2 port are used as query signals during programming to achieve unidirectional or bidirectional transmission.

2.1 One-way transmission

One-way transmission means that the data flow of the communication port is only in one direction, that is, the data received from U1_L is sent from U2_H, or the data received from U2_H is sent from U1_L. It is relatively simple to program software in this way. Now, taking U1_L only receiving data from external devices and U2_H only sending data to external devices, the flow chart of data transmission between the two microcontrollers is shown in Figure 3. Among them, P2.2 of U1_L is used as a query signal for transmitting new data to U2_H (P2.5 of U2_H), P2.2 = "0" indicates that there is new data, and P2.2 = "1" indicates that there is no new data; P2.2 of U2_H is used as a query signal for receiving U1_L data (P2.5 of U1_L), P2.2 = "0" indicates that new data can be received, and P2.2 = "1" indicates that new data cannot be received. If the interrupt method is used, the query signals of the two microcontrollers are simpler. It only needs Ul_L to query U2_H whether it can receive data signals, and U2_H does not need to query the query signal of U1_L.

2.2 Bidirectional transmission

Bidirectional transmission means that the communication port can receive and send data at the same time. The data flow is bidirectional. Ul_L and U2_H both receive and send data. The software programming of this method is relatively complex, especially when the bidirectional data transmission adopts the query method. The query signal between the microcontrollers is even more complicated. Taking the bidirectional query method as an example, the flow chart of data transmission between the two microcontrollers is shown in Figure 4. The process of U2_H is the same as that of U1_L. Among them, the query signal when U1_L transmits data to U2_H is the same as the definition of unidirectional transmission. P2.3 of U2_H is used as the query signal for transmitting new data to U1_L (P2.4 of U1_L). P2.3 = "0" indicates that there is new data, and P2.3 = "1" indicates that there is no new data; P2.3 of Ul_L is used as the query signal for receiving U2_H data (P2.4 of U2_H). P2.3 = "0" indicates that new data can be received, and P2.3 = "1" indicates that new data cannot be received. If the interrupt method is adopted, the query signal can be reduced and the programming can be simplified.

2.3 Notes on application

If the handshake between two MCUs is interrupted, since U2_H sends data to the outside faster than U1_L receives external data, when U1_L transmits data to U2_H, there is no need to consider the state of U2_H. When U2_H transmits data to U1_L, since U2_H receives external data faster than U1_L sends data to the outside, U2_H must query the state of U1_L, that is, whether U1_L is in the state of receiving U2_H data. Otherwise, U2_H cannot transmit data to U1_L.

If used as an RS_485 communication interface, only a slight change is needed to the circuit in Figure 2, adding read and write control to the 75176 chip. At the same time, the MCU connected to the main communication device in the two MCUs is used as the host, and the two MCUs are coordinated to receive or send data through a bit of the P2 port.

It is worth noting that the baud rate converter will be subject to certain restrictions in different applications. When using it, pay attention to the following points:

① When the baud rate is very high, consider whether the serial port of the microcontroller can be realized;

② When changing from a high baud rate to a low baud rate, consider whether the microcontroller with a low baud rate can send data without losing it;

③ When bidirectional conversion is performed, consider the above situation, as well as the size of the program and the impact of the execution time on the bidirectional transmission of data. Calculate whether the two microcontrollers can achieve the conversion without losing data, and leave a margin in time;

④ When querying, pay attention to the relationship between the handshake signals, and do not read the same data repeatedly, so that the data is repeated;

⑤ When the baud rate is different, the microcontroller can use different crystal oscillator frequencies.

2.4 Examples and source programs

In actual use, if you encounter the situation shown in Figure 1, you need a baud rate converter to convert the communication data with a baud rate of 172.8kbps into a baud rate of 115.2kbps, and then transmit it to the host computer. The actual circuit used is shown in Figure 2. In this example, in order to prevent data loss due to receiving data faster than sending data at a certain time, 8 data areas are added to the program of the U2_H microcontroller as a buffer for receiving data.

3 Conclusion

Through long-term communication experiments and practical applications, the designed baud rate converter scheme is feasible, the communication is reliable, and there is no data loss. In some systems, due to the special communication baud rate, when there is a baud rate mismatch between devices, the baud rate converter can realize communication between devices with different baud rates. By changing the crystal frequency of the microcontroller, the conversion of various baud rates (within the range allowed by the microcontroller) can be satisfied.

Reference address:Multi-machine parallel communication system based on 89S51 single chip microcomputer

Previous article:Driving OLED display based on SSD1303 and AT89C51
Next article:Universal Chinese Character Text Broadcasting System Designed Based on Single Chip Microcomputer

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
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号