Design of serial port expansion method for 51 single chip microcomputer

Publisher:范隆Latest update time:2012-03-10 Source: 微计算机信息 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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

Reference address:Design of serial port expansion method for 51 single chip microcomputer

Previous article:Interface Design between AT89S52 and CF Card
Next article:The Principle and Application of Single Chip Microcomputer Real-time Clock Circuit

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号