In the development and application of single-chip microcomputers, we often use a master-slave control structure. A PC is used as a host computer to control multiple single-chip microcomputer systems. The powerful and resource-rich PC can be used to conveniently design the human-machine interface and manage and output the database, while the single-chip microcomputer performs flexible control and measurement. In some applications, these single-chip microcomputer systems are installed close together. Because the distance between the single-chip microcomputers is close to each other, the communication wiring is very short. At this time, the one-to-many multi-machine communication between the PC and the single-chip microcomputer can avoid the RS 485 communication that requires special switching equipment, or the complex CAN communication. Instead, the competition control circuit is designed and the response communication program is adopted, so that multiple single-chip microcomputers can directly share an RS 232 interface with the PC to achieve reliable asynchronous serial communication.
1 Multi-MCU Communication Structure
The structure of multiple MCUs sharing RS 232 interface to communicate with PC is shown in Figure 1, which consists of three parts: serial communication interface, anti-competition circuit and lower computer.
The key to multiple MCU systems sharing the RS 232 bus is how to avoid competition. For the receiving end, after the level conversion by the RS 232 level conversion chip, it can be directly connected to the Rxd end of all MCU serial ports. The PC sending information to the MCU is equivalent to broadcasting to all MCUs, and there is no competition. However, the sending end of the MCU cannot be directly connected in parallel to the TnIN end of the serial port conversion chip MAX232, otherwise the system will be extremely unreliable. Regardless of the reason, if two or more MCU systems send information to the PC at the same time, bus competition will occur and the RS 232 bus signal will be chaotic. Therefore, the anti-competition control circuit in the figure is specially designed to prevent bus competition to ensure that only one MCU system occupies the RS 232 sending port at any time.
2 Control circuit to prevent competition
The control circuit to prevent competition is shown in Figure 2. TxdA, TxdB, and TxdC are the Txd terminals of microcontroller A, microcontroller B, and microcontroller C, respectively, which are connected to the three input terminals of the 74HC125 with a 3-state driver. The three output terminals of the 74HC125 are also connected to the T2IN terminal of the RS 232 level conversion chip MAX232. A, B, and C are the serial port output control terminals of the three microcontrollers (low level is valid, assuming that they are all connected to the P10 port), which are composed of 74HC00 4+2 NAND gates and 74HC32 4+2 OR gate circuits.
The three control terminal signals output by the control circuit to 74HC125 are defined as OEA, OEB, and OEC, corresponding to the three microcontroller serial port control signals A, B, and C. The logical relationship is:
The truth table of the control circuit is shown in Table 1.
From the truth table, we can see that the competition prevention control circuit ensures that when A is valid, only TxdA is allowed to pass through 74HC125 and the other two signals are prohibited. Similarly, when B is valid, only TxdB is allowed to pass, and when C is valid, only TxdC is allowed to pass, and the other two signals are prohibited. It ensures that only one microcontroller serial port occupies the RS 232 transmission channel at any time, and other microcontrollers cannot occupy the RS 232 transmission channel, effectively preventing the occurrence of competition. [page]
3 Communication procedures to prevent competition
3.1 Multi-machine communication protocol.
The multi-machine communication protocol is to make the single-chip microcomputer occupy the RS 232 transmission channel in a time-sharing manner. With the cooperation of the anti-competition control circuit, the PC can only communicate with one single-chip microcomputer at any time to ensure smooth communication. The communication adopts the handshake communication method, and the communication protocol is as follows:
Each frame of information is 8 bytes, of which the first byte is the signature (here the character "L"), the second byte is the address code, the third byte is the command code, the fourth to seventh bytes are data bytes, and the eighth byte is the checksum (the XOR sum of the bytes starting from the address code).
For example, if a PC sends a call to a single-chip microcomputer system: "L", "A", 01H, 00H, 00H, 00H, 00H, 40H, where "A" (41H) indicates a call to single-chip microcomputer A, 01H is a command, the four 00Hs are the parameters of the command, and 40H is the checksum.
After receiving the characteristic code "L", the single-chip computer starts to receive the subsequent 7 bytes of information and calculates the checksum of these 7 bytes. After the complete frame of the call code is verified, the address code is checked. Single-chip computer A checks the address code to be "A", confirms that it is a call to this machine, and responds immediately, pulling down P10 (signal A). This machine can monopolize the RS 232 bus transmission channel and communicate serially with the PC according to the communication protocol. After the communication is completed, P10 (signal A) is restored to restore the RS 232 bus transmission channel to the idle state. Single-chip computer B and single-chip computer C will exit after checking that the address code is not the address of the local machine, and maintain the receiving state.
3.2 Host computer communication program
The host computer and the slave computer adopt the answering communication mode. After the host computer sends a call code to a slave computer, it starts the timer of the serial port query, waits for the slave computer to execute the command and return information according to the command requirements. If the information returned by the microcontroller can be queried after the timing time, the information is taken out for processing, otherwise it is considered that the microcontroller is wrong. The host computer communication process is shown in Figure 3.
Figure 4 is a timing diagram of the communication between the host computer and three single-chip microcomputers.
3.3 Lower computer communication program
After the lower computer receives the command, the time it takes to execute the command and return information must be less than the waiting query time of the upper computer, otherwise it will be treated as an error. The communication process of the lower computer is shown in Figure 5.
4 Conclusion
By adopting the anti-competition control circuit and responsive programming, when multiple single-chip computers share the RS 232 interface, each single-chip computer will occupy the RS 232 bus transmission channel in a time-sharing manner, effectively avoiding the competition of the serial bus. The control circuit is composed of ordinary 74HC series chips, with simple circuits, easy implementation and reliable communication. The author used this circuit in the development of the "Signal Microcomputer Monitoring System Board Fault Locator" project. The control boards of three lower computers (51 series single-chip computers) were installed in the same chassis, and the embedded tablet computer was used as the upper computer to communicate serially with the three lower computers. Practice has proved that the circuit can work stably and reliably.
Previous article:Design of battery safety detection system based on single chip microcomputer
Next article:Design of Temperature Measurement Circuit Using Single Chip Microcomputer
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Features of Ad Hoc Networks
- APWM
- Power supply obstacles - practical experience
- Industrial DACs: The Evolution of 3-Wire Analog Output
- Chapter 5 GD32L23x I2C Usage - Read and Write DHT12
- Industrial computer case
- EEWORLD University Hall----Live Replay: Datang NXP-DNS Battery Management Chip Solution
- 5G Network Slicing
- Static Electricity Protection Measures in Circuits
- Portable energy storage power supply-Nanxin Semiconductor enters the market with strength