Application of the hottest sp2338 serial port expa

2022-08-07
  • Detail

Application of sp2338 serial port expansion chip in automobile traveling data recorder

in the automobile traveling data recorder composed of single chip microcomputer, in order to meet the needs of different users, the recorder needs to be configured with more than three serial ports (including three) such as serial port printing, serial port communicating with upper computer and GPS communication interface, which can not be met by directly using the functions of single chip microcomputer. Using one piece of sp2338 can solve this problem well

1. Introduction to sp2338

sp2338 serial port expansion chip can expand one serial port of a common 51 series single chip microcomputer to three independent full duplex serial ports, and the baud rate of the three serial ports has reached 9600bps. Sp2338 adopts the general protocol (1 start bit, 8 data bits and 1 stop bit). At the same time, the interface between the chip and the MCU is also very simple

sp2338 has four serial ports, a mother serial port and three sub serial ports, all of which are full duplex serial communication ports, allowing simultaneous receiving and sending of data. The mother serial port is connected with the serial port of the 51 single chip microcomputer that needs to be expanded, and the sub serial port is connected with other serial port devices. In this way, the single chip microcomputer with only one serial port can be connected with three serial port devices. Sp2338 has two sending address lines and two receiving address lines to select the sending serial port and receiving serial port, as shown in Figure 1

when the single chip microcomputer wants to send data to the serial port device, its working process is:

1) first send address signals to the serial port address lines adri0 and adri1 of sp2338 (adri0 and adri1=00 sub serial port 0, adri0 and adri1=01 sub serial port 1, adro0 and adro1=10 sub serial port 2); Then send data to the communication line of the parent serial port connected with itself

2) the sp2338 mother serial port will send the data to the corresponding sub serial port according to the status of adri0 and adri1 after receiving the data from the SCM serial port

3) the sub serial port sends the data to the connected serial port equipment

when the serial port device sends the meaning of thermal insulation material to the single chip microcomputer, its working process is:

1) when a sub serial port of sp2338 receives data from the serial port device, it sends it to the parent serial port

2) the mother serial port of sp2338 sends the data to the serial port of the single chip microcomputer, and sends the address of the sub serial port on the adro0 and adro1 lines at the same time

3) the single chip microcomputer determines which serial port device sent the signal according to the signals on the sp2338 receiving address lines adro0 and adro1

since each serial port of sp2338 has its own transmit buffer and receive buffer, the expanded three serial ports can communicate independently at the same time, just as a single chip computer has three serial ports at the same time. If a single chip computer has two serial ports, it can be expanded to six serial ports with two sp2338

sp2338 the baud rate of each sub serial port can reach 9600bps. Sp2338 needs to be equipped with a crystal oscillator when it works. The frequency of the crystal oscillator FOSC has the following relationship with the baud rate of the parent serial port:

k parent =1920*fosc,

has the following relationship with the baud rate of the sub serial port:

k child =480*fosc,

therefore, if the sub serial port adopts 9600 baud rate, fosc=20mhz according to the above formula. The baud rate of the mother serial port must reach 388400bps. In this way, the baud rate of the single chip microcomputer serial port connected to the sp2338 mother serial port reaches 388400bps. If the single chip microcomputer adopts non-11. If the working crystal oscillator of 0592m, the baud rate will have deviation. However, the allowable baud rate error of sp2338 is 2. 5%。 In the vehicle traveling data recorder developed by me, the system uses 24MHz working crystal oscillator, uses timer 2 as baud rate generator, and sets: rcap2h=0xff, rcap2l=0xec, which can communicate normally

since some single-chip computers use crystal oscillators of other specifications to work, they can not reach such a high baud rate. If you want to reduce the baud rate of the mother serial port, you should not only reduce the baud rate of the single-chip computer, but also recalculate FOSC according to the above formula and replace the working crystal oscillator of sp2338 with an appropriate one

2. Application of sp2338 in vehicle traveling data recorder

1) Figure 2 is the hardware connection logic diagram

as sp2338 is the adapter between the serial port of single chip microcomputer and other serial port devices, sp2338 is tx3 connected to the rxdm of single chip microcomputer, and the RX3 of sp2338 should be connected to the txdm of single chip microcomputer

2) software implementation

since sp2338 can work normally once powered on, no initialization operation is required, so it does not need to be initialized in the software. The mother serial port of sp2338 and the three sub serial ports used for packaging perishable fresh food exchange data continuously. Therefore,

① when sp2338 receives data from the serial port equipment and sends it to the serial port line of the single chip microcomputer through the mother serial port, the single chip microcomputer should read the data in time and determine the status of adro0 and adro1, otherwise it is easy to cause data errors. Therefore, it is necessary to use serial port interrupt on the single chip microcomputer

② when the single-chip microcomputer sends data to the external serial port equipment, it must first send a byte of data to the sub serial port 0, then send a byte of data to the sub serial port 1, then send a byte of data to the sub serial port 2, and then execute a NOP command to send data. This cycle is followed. If there are no three external serial port devices, the processing is as follows:

a. if the upper computer only needs to send data to a sub serial port, first send a byte of data to the serial port, then execute four 'NOP' commands, and then send the second data to the sub serial port

b. if the upper computer only needs to send data to the two sub serial ports, it can send one byte of data to the two serial ports respectively, execute three NOP commands, and then send the next byte of data to the two serial ports respectively

the serial port interrupt flow is shown in Figure 3

3. Conclusion

I used an sp2338 in the development of the automobile traveling data recorder, which expanded one serial port of the single chip microcomputer into three full duplex serial ports, so that the automobile traveling data recorder can communicate with the serial printer, upper computer, GPS and other serial port equipment, which conforms to the relevant provisions of the national gbt/automobile traveling data recorder standard, and achieved satisfactory results

references

1 xuaijun, pengxiuhua. High level language C51 application program design. Electronic Industry Press, 1998

2 mazhongmei et al. The C language application program of single chip microcomputer is designed according to the introduction of the company. Beijing University of Aeronautics and Astronautics Press, 2000 Revision (end)

Copyright © 2011 JIN SHI