Application of SP2338 serial port expansion chip in car driving recorder

1. Introduction to SP2338
The SP2338 serial port expansion chip can expand one serial port of the ordinary 51 series MCU into three independent full-duplex serial ports, and the baud rate of the three serial ports has reached 9600bps. SP2338 uses a general protocol (1 start bit, 8 data bits, 1 stop bit), and at the same time, the interface of the chip when it is connected to the single-chip microcomputer is also very simple.
SP2338 has a total of four serial ports, a female serial port and three sub-serial ports, all of which are full-duplex serial communication ports, allowing data to be received and sent simultaneously. The mother serial port is connected to the serial port of the 51 single chip microcomputer that needs to be expanded, and the sub serial port is connected to other serial port devices, so that the single chip microcomputer with only one serial port can be connected to three serial port devices. SP2338 has two sending address lines and two receiving address lines to select the sending serial port and the receiving serial port, as shown in Figure 1.
When a single-chip microcomputer wants to send data to a serial device, its working process is:
1) Send address signals to the serial address lines ADRI0 and ADRI1 of SP2338 (ADRI0, ADRI1 = 00 sub-serial port 0, ADRI0, ADRI1 = 01 sub-serial port 1, ADRO0, ADRO1 = 10 sub-serial port 2) Send data on the communication line of the female serial port;
2) After the serial port of SP2338 receives the data sent from the serial port of the microcontroller, it sends the data to the corresponding sub-serial port according to the status of ADRI0 and ADRI1;
3) The sub-serial port sends the data to the connected serial device.
When the serial device sends data to the microcontroller, the working process is:
1) When a sub-serial port of SP2338 receives data from a serial device, it is sent to the female serial port;
2) The 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;
3) The single chip determines which serial port device sends out the signal on the address lines ADRO0 and ADRO1 received by SP2338.
Since each serial port of SP2338 has its own send buffer and receive buffer, the three extended serial ports can communicate completely independently at the same time, as if the single-chip computer has three serial ports at the same time, if a single-chip computer has two Serial port, then with two SP2338 can be expanded to 6 serial ports.
The baud rate of each sub-serial port of SP2338 can reach 9600bps. SP2338 needs to be equipped with a crystal oscillator. The frequency of this crystal oscillator F OSC has the following relationship with the baud rate of the female serial port:
K mother = 1920 * Fosc,
The relationship with the sub-serial port baud rate is as follows:
: K 子 = 480 * Fosc,
Therefore, if the sub-serial port uses 9600 baud rate, according to the above formula, Fosc = 20MHz. The baud rate of the female serial port must reach 388400bps. In this way, the baud rate of the serial port of the single-chip microcomputer connected to the serial port of SP2338 reaches 388400bps. If the single-chip microcomputer uses a working crystal oscillator other than 11.0592M, the baud rate will be biased. However, the SP2338 allows a baud rate error of 2.5%. In the car driving recorder I developed, the system uses a 24MHz working crystal oscillator, using timer 2 as a baud rate generator, and set: RCAP2H = 0xFF, RCAP2L = 0xEC, normal communication.
Since some MCUs work with crystal oscillators of other specifications and cannot achieve such a high baud rate, if you want to lower the baud rate of the serial port of the mother, not only to lower the baud rate of the MCU, but also according to the above Formula, recalculate Fosc, and replace the working crystal of SP2338 with a proper one.
2. Application of SP2338 in car driving recorder

1) Figure 2 is the logic diagram of hardware connection. Because SP2338 is the adapter between the serial port of the microcontroller and other serial devices, so relative to the microcontroller, SP2338 is the connection between Tx3 and the RXDM of the microcontroller, and Rx3 of the SP2338 is connected to the TXDM of the microcontroller. 2) Software implementation Since SP2338 can work normally when powered on, it does not need any initialization operation, so it does not need to be initialized in software. The serial port of SP2338 and the three serial ports exchange data continuously, so
â‘  When the SP2338 receives data from the serial port device and sends it to the serial port line of the single-chip microcomputer through the serial port, the single-chip microcomputer should read the data in time and determine the status of ADRO0 and ADRO1, otherwise it will easily cause data errors. Therefore, a serial port interrupt is used on the microcontroller.
â‘¡ When the MCU sends data to an external serial device, it must first send a byte of data to sub-serial port 0, then send a byte of data to sub-serial port 1, and then send a byte of data to sub-serial port 2, Then execute a NOP command to send data in sequence, and follow the cycle. If there are not three external serial devices, they are processed as follows:
A. If the host computer only needs to send data to a sub-serial port, first send a byte of data to the serial port, and then execute 4 'NOP' commands, and then send the second data to the sub-serial port.
B. If the host computer only needs to send data to the two sub-serial ports, it can send one byte of data to the two serial ports, and then execute three NOP commands, and then send the next byte of data to the two serial ports.
Serial port interrupt flow chart 3 is shown.


4. Conclusion I used a piece of SP2338 in the development of the car driving recorder, and extended a serial port of the single-chip computer into three full-duplex serial ports, so that the car driving recorder can communicate with serial devices such as serial printers, host computers and GPS , In line with the relevant provisions of the national GBT / 19056-2003 "Car Driving Recorder" standard, and achieved satisfactory results.

The 0-10V dimmable series of Constant Voltage Class 2 LED Drivers from ZHPOWER offers both UL 8750 Listed and CLASS 2 rated. With universal input voltage ranging from 120VAC, the series of 12V/24V DC led drivers are designed for commercial, industrial and residential applications. Our 0-10V dimming delivers smooth flicker-free linear dimming down to 1% with most LED`s and a wide variety of compatible dimmers.

0~10V Dimmable Led Driver

Dimmable Led Driver,Ul Class 2 Dimmable Driver,Dimmable Led Driver 48W,Led Driver Dimmer 80W

Shenzhenshi Zhenhuan Electronic Co Ltd , https://www.szzhpower.com

Posted on