1 Introduction
In the process of studying the gas accumulation simulation test bench in the mining area, the author designed a master-slave multi-machine mining control system structure. The master-slave multi-machine control system is a common structure in real-time control systems. It has the advantages of high reliability and flexible structure. When a single serial port 51 single-chip microcomputer is selected to form this master-slave multi-machine system, the 51 single-chip microcomputer may need to communicate with the host computer on the one hand and with the lower computer on the other hand. At this time, it is necessary to expand the serial channel. This article specifically introduces two serial channel expansion methods.
2 Serial port expansion method
The commonly used standard 51 single-chip microcomputer contains only one programmable full-duplex serial communication interface, which has all the functions of UART. This interface circuit can not only send and receive data at the same time, but also can be used as a synchronous shift register. When this type of single-chip microcomputer is used to form a distributed multi-level application system, the serial port resources of the device itself are not enough. In actual development, the author consulted relevant information and summarized the following two common and effective serial channel expansion methods.
2.1 Expansion method based on SP2538
SP2538 is a dedicated low-power serial port expansion chip. This chip is mainly launched to solve the problem that there are many peripheral intelligent modules and devices based on UART serial port communication, while the original UART serial ports of the single-chip microcomputer or DSP are too few. Using this device, the single serial port of the existing single-chip microcomputer or DSP can be expanded to 5 full-duplex serial ports. The method of use is simple and efficient.
When using SP2538 to expand the serial channel, the mother serial port baud rate K1 = 2880 * Fosc_in, the unit is MHz, and Fosc_in is less than 20.0MHz. When the SP2538 input clock Fosc_in = 20.0MHz, the mother serial port can adapt to the host computer's two standard baud rate inputs of 56000bps and 57600bps. The slave serial port baud rate K2 = 480 * Fosc_in.
The mother serial port and all slave serial ports are TTL level interfaces, which can directly match other microcontrollers or TTL digital circuits. If you need to connect to a PC, you must add a level conversion chip such as MAX202, MAX232, etc. SP2538 has a built-in power-on reset circuit and a closable watchdog monitoring circuit. The host computer writes command word 0x10 to feed the dog, writes command word 0x15 to close the watchdog, and the watchdog is in an active state after the first power-on or writes command word 0x20 to activate the watchdog monitoring function. The host computer can reset the chip at any time through the chip reset instruction 0x35, and can also put the chip into micro-power sleep mode at any time through the chip sleep instruction 0x55 to reduce system power consumption. After the first power-on, the chip will not enter the sleep mode by itself, but can only be awakened by the host computer sending a byte of data through the mother
serial port. Other sub-serial ports do not have this function. Figure (1) is the circuit connection between the AT89C52 microcontroller and the SP2538. In the figure, the full-duplex serial port of the AT89C52 is connected to the mother serial port 5 of the SP2538, which is also used as the command/data port. The ADRI0, ADRI1, and ADRI2 of the SP2538 are connected to the P2.3, P2.4, and P2.5 ports of the AT89C52 respectively, which can be used to select the corresponding serial port 0~4 for sending data; ADRO0, ADRO1, and ADRO2 are connected to P2.0, P2.1, and P2.2 to determine which serial port the received data comes from. The clock frequency of SP2538 is selected as 20.0MHZ. At this time, the baud rate of the mother serial port 5 is 57600bps, and the baud rate of the serial ports 0~4 is 9600bps.
The following is the interface program related to the above hardware circuit. The program is compiled in A51 assembly language. The program only explains the operation of the slave serial port 0 (TX0, RX0) in interrupt mode. Other slave serial ports are similar.
TBLOCK DATA 20H
RBLOCK DATA 30H
LENGTH DATA 14H
…
TXR_REV_SEND: CLR ES
JBC RI,RECEIVE
CLR TI
MOV A,@R0
CLR P2.0 ; Before writing data to "SBUF", the address of the slave serial port to be sent must be set first
CLR P2.1
CLR P2.2
MOV SBUF,A
DJNZ R2,NEXT
SJMP $
NEXT: INC R0
RETI
RECEIVE: MOV A,P2
AND A,#31H ; Determine whether it is slave serial port 0
JNZ ELSE
MOV A,SBUF
MOV @R1,A
INC R1
RETI
Figure (1) Circuit connection between AT89C52 and SP2538 [page]
2.2 Serial port expansion method based on Intel8251
The serial port expansion method based on SP2538 above can be said to be a serial expansion method, and the expansion method based on Intel8251 here is a parallel method. Intel8251 is a universal synchronous/asynchronous transmitter (USART), and its working mode can be set by programming. It can work in synchronous or asynchronous serial communication mode and can automatically complete the frame format.
Intel8251 has an independent receiver/transmitter. In asynchronous mode, the clock CLK input used to generate the internal timing of 8251 should be at least 4.5 times the transmit or receive clock. The receive/transmit (RXC/TXC) clock should be 1, 16 or 64 times the baud rate (set by the working mode word of 8251).
Figure (2) shows the circuit principle of using Intel 8251 to expand a serial channel. In the figure, the 11.0592MHZ crystal oscillator is divided by ALE6 and combined to generate a clock frequency of 1.8432MHZ, which is used as the clock input of 8251 and 8253 respectively. If the communication baud rate of 8251 is set to 9600bps and the baud rate factor is 16, a receive/send clock frequency of 153.6KHZ is required, which can be generated by OUT0 of 8253.
The following A51 program segment illustrates how to set up 8253 to generate a 153.6KHZ square wave, and how to use 8251 to send and receive data:
; Program segment for setting up 8253:
MOV A,#36H ; Counter 0 outputs square wave control word
MOV DPTR,#0FFFFH ; Points to control word register
MOVX @DPTR,A
MOV DPTR,#0FFFCH ; Points to 0 counter address
MOV A,#0DH
MOVX @DPTR,A
MOV A,#0
MOVX DPTR,A
SETB P1.0
; Program segment for operating 8251:
…
START: MOV DPTR,#7FFFH ; 8251 control and command port address
MOV A,#5EH ; One stop bit, odd parity, 8-bit data, asynchronous*16
MOVX @DPTR,A ; Write mode word MOV
A,#15H
MOVX @DPTR,A ; Command word, start sending and receiving
...
LOOP: SJMP LOOP ; Wait for 8251 interrupt
8251_INT: ; Context protection
MOV DPTR,#7FFFH
MOV A,@DPTR
JB ACC.0,TX_INT
JB ACC.1,RX_INT
INT_EXIT: ; Restore context
RETI
; Send data
TX_INT: MOV DPTR,#7FFEH ; 8251 data port address
MOV A,20H
MOVX @DPTR,A
…
AJMP INT_EXIT
; Receive data
RX_INT: MOV DPTR,#7FFEH
MOVX A,@DPTR
MOV 30H,A
…
AJMP INI_EXIT
Figure (2) Principle of hardware circuit for extending serial channel using 8251
3 Conclusion
The application of multi-level distributed systems with single-chip microcomputer as the core is becoming more and more widespread. The two serial port expansion methods discussed above provide a good solution for such multi-serial port application fields. In practice, the author uses the expansion method based on SP2538 to design a multi-level distributed mining control system for the gas accumulation simulation test bench in the mining field, and the effect is good.
References
[1] Sun Heping, Yang Ning, Bai Jing, Principles of Single-Chip Microcomputers and Interface Technology, Metallurgical Industry Press, 2003.1
[2] Hu Hancai, Principles of Single-Chip Microcomputers and Interface Technology, Tsinghua University Press, 1996.7
[3] SP2538 Data Sheet, Chengdu Shipu Technology Co., Ltd., 2003.2.12
Previous article:Interface Design between AT89S52 and CF Card
Next article:The Principle and Application of Single Chip Microcomputer Real-time Clock Circuit
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
- [STM32F769Discovery development board trial] Discussion and application of DMA2D screen refresh efficiency
- Using Energia to develop MSP430F5529LP under Windows 10 Basic process and problems encountered
- Wi-Fi 6E has been launched. What is the difference between it and ordinary Wi-Fi?
- uboot operates gpio level
- UNI-T UT70B Multimeter Schematic Diagram and Instruction Manual (EN)
- DIY Music Box (Ask a master to help come up with an attractive title)
- Can you analyze the circuit for me?
- RSL10 information summary, sharing and exchange
- RF PCB Simulation Cookbook
- This year's Mid-Autumn Festival and National Day will not leave Shanghai