Several Solutions for Insufficiency of Host Serial Communication Interface in Embedded System

Serial interface devices are widely used in industrial control, home security, GPS satellite positioning and navigation, and meter reading of water, electricity, and gas meters due to their advantages of flexible control, simple interface, and less system resources. In these embedded systems, there may be many slave devices that communicate with the host through serial interfaces, such as GPRS MODEM, infrared sending and receiving modules, RS485 bus interfaces, and so on. This makes developers often face the problem of insufficient host serial communication interface in embedded systems. For this problem, this article introduces several common solutions.

Serial interface devices are widely used in industrial control, home security, GPS satellite positioning and navigation, and meter reading of water, electricity, and gas meters due to their advantages of flexible control, simple interface, and less system resources. In these embedded systems, there may be many slave devices that communicate with the host through serial interfaces, such as GPRS MODEM, infrared sending and receiving modules, RS485 bus interfaces, and so on. This makes developers often face the problem of insufficient host serial communication interface in embedded systems. For this problem, this article introduces several common solutions.

software simulation

Extend serial port by using parallel port to serial port

Serial port expansion based on Intel8251

The Intel8251 is a Universal Synchronous/Asynchronous Transmitter (USART) that works in a programmable way and has a separate receiver/transmitter. It can work in synchronous or asynchronous serial communication mode, automatically complete the frame format, with odd and even check and error detection circuits.

Serial port expansion based on TL16C554

TL16C554 is a 4-channel asynchronous transceiver integrated chip produced by TI. The control of the TL16C554 serial channel is realized by programming the control registers LCR, IER, DLL, DLM, MCR and FCR. These control words determine character length, number of stop bits, parity, baud rate, and modem interface. The control registers can be written in any order, but the IER must be written last because it controls interrupt enable. The Baud Rate Generator (BRG) within the serial channel allows the clock to be divided by any number between 1 and 65535. The BRG determines the standard baud rate based on one of its three common frequencies. 16C55x series chips also include 16C550 and 16C552, which can expand 1 and 2 serial ports respectively.

Expansion of serial port with serial port

Based on the serial port expansion of GM8123/25 series chips, GM8123/25 series serial port expansion chips can realize serial port expansion in full hardware, and the communication format can be set, and is compatible with the standard serial communication format. GM8125 can expand 5 standard serial ports, select serial port expansion mode through external pins: single-channel working mode and multi-channel working mode. In single-channel mode, there is no need to set the communication format of the chip, the sub-serial port and the mother-serial port work at the same baud rate, only one group of sub-serial ports and the mother-serial port are allowed to communicate at the same time, and the working sub-serial port is selected by the address line. The single-channel working mode is suitable for systems where all slaves do not need to communicate at the same time, and the communication process is completely controlled by the host.

In multi-channel mode, each sub-serial port has the same baud rate, allowing all sub-serial ports to communicate with the mother serial port at the same time. When sending, the address line selects the sub-serial port used to send data; when receiving, the sub-serial port can actively respond to the data sent by the slave, and then send it to the host through the mother serial port, and at the same time, the address line returns the address of the sub-serial port that received the data. After receiving the data from the sub-serial port, it can be judged by which slave the data is sent according to the state of the address line. In multi-channel working mode, the working mode of the chip should be set before data communication, including serial frame format setting and communication baud rate setting. The working mode of the chip can be set through the cooperation of the serial port and the control pins. When the pin MS is 0, and STADD2 “STADD0 is 000, the command word is written, and the pin MS is 1, STADD2” When the STADD0 is 000, the command word is read. . When setting the working mode, the frame format of the chip and the working baud rate of the mother serial port are consistent with the last data communication; the frame format after reset is 11bit, and the baud rate of the mother serial port is 7200bps.

Serial port expansion based on SP2338

SP2338 is a universal asynchronous serial port expansion chip designed with low power consumption CMOS technology. It can easily expand the original 1 serial port of the host into 3 new full-duplex serial ports. SP2338 is suitable for multi-serial system with 1 start bit, 8 data bits and 1 stop bit, which means its frame format is not programmable. The host selects any one of the three sub-serial ports by changing the state of the ADRI1 and ADRI0 address lines, and the addresses of the three sub-serial ports are 00, 01, and 10 respectively. Address 11 is used to execute the reset command 0x35 or 0xB5 of the SP2338 chip itself, the sleep command 0x55 or 0xD5, and the delay command 0x00. The SP2338 can be woken up by writing any data to any receiving port in RX0 “RX3, but since the wake-up time of the SP2338 takes about 25ms, the data used for chip wake-up will not be received by the host. Therefore, you can send a word first. Section data is used to wake up the chip, and normal data transmission can be performed after a delay of 25ms.

Unused input ports, such as RX0, RX1, RX2, etc., must be connected to VCC; unused output ports, such as TX0, TX1, TX2, etc., must be left floating; unused ADRI0, ADRI1 must be connected to GND. The timing of the host sending and receiving data is: after the host TX3 receives a byte, it should immediately read the status of the output addresses ADRO0 and ADRO1 of SP2338 to determine which sub-serial port the received data comes from; when the host sends data, first select a certain serial port through ADRI0 and ADRI1. A sub-serial port, and then write the data to be sent to TX3.

Several Solutions for Insufficiency of Host Serial Communication Interface in Embedded System
Figure 1 Schematic diagram of the extended serial port method designed in this paper

The expansion method designed in this paper In the process of circuit design, this paper designs a scheme that suits the needs of its own system and expands one serial port into three serial ports, as shown in Figure 1. Among them, 4001 is a four-2-input NOR gate, and 40106 is a six-Schmitt trigger. Pins 4 and 9 of 4001 are the RXD and TXD of the host respectively, pins 2 and 9 of 40106 are TXD0 and RXD0 of the sub-serial port, pins 6 and 11 are the TXD1 and RXD1 of the sub-serial port, and pins 4 and 13 are the sub-serial ports. TXD2 and RXD2 of the serial port.

According to the connection method of the figure and the derivation of logical algebra, it can be obtained that the state of RXD is equal to the state of 9 pins, 11 pins and 13 pins of 40106. When any of the 9 pins, 11 pins, and 13 pins of the 40106 has a data signal, because in asynchronous serial communication, the pin state is high when there is no data transmission, so the RXD can receive a data signal. The data state on that pin. The status of pins 2, 4, and 6 of 40106 is equal to the status of TXD, so you can use pins 2, 4, and 6 of 40106 as the TXD of the sub-serial port.

This design is suitable for the situation where the host sends data to multiple serial devices at the same time, but the slave devices do not send data to the host at the same time. By adding a few more signal lines, you can distinguish which slave device to send data to and which slave device the received data comes from. In the system of this paper, the host is the initiator of communication, and it is predictable which slave device the received data comes from. Therefore, it is only necessary to add three more signal lines to control the enabling of the slave device.

Comparison of several methods

When the serial port of the system needs to be expanded, the method of using a multi-serial port microcontroller is the easiest to think of. Since the serial port is integrated inside the microcontroller, the device is small in size and has high anti-interference ability, but the multi-serial port microcontroller is usually expensive, and if it is a model that the developer is not familiar with, the developer needs to re-learn and purchase it. The supporting development tools extend the product development cycle and increase the product development cost.

The software simulation method occupies less system resources, has low cost and is easy to implement. But its sampling frequency is low, it is difficult to ensure the correctness of data, and generally cannot simulate too high baud rate. The parallel port expansion serial port method is more powerful, can provide MODEM control signals, and has high communication speed, but the control is complicated, occupies more port resources of the MCU, and the price is also high.

Using the serial port to expand the serial port, the control is simple, the control line can be minimized, it does not need to occupy too many host system resources, and the versatility is strong, the performance is stable, and the correctness of the data can be guaranteed. The disadvantage of GM812x is that it does not meet the requirements of ultra-low power consumption applications; in multi-channel mode, the working baud rate of all sub-serial ports can only be set to a uniform value, which is not suitable for the different working baud rates of each slave machine, and requires simultaneous operation. working system. Although SP2338 can meet the requirements of low power consumption, its sub-serial port baud rate also needs to be set to a unified value, and the data frame format cannot be programmed, and the maximum baud rate is only 9600bps.

In the method proposed in this paper, the serial characteristics of each sub-serial port are the same as that of the mother serial port, which is easy to use, occupies less system resources, is easy to control (at least 2 control signals extend 3 serial ports), and has good stability. Its power consumption depends on 4001 and 40106, and their power consumption is in mA level. The maximum baud rate depends on the response speed of 4001 and 40106. The maximum response delay of 4001 and 40106 is 250ns, so the theoretical maximum baud rate can reach 4Mbps. This method has been successfully applied to the three-meter remote transmission system. The disadvantage of this method is that it cannot be used in systems where the slaves work at different baud rates and require simultaneous work.

Epilogue

In this paper, a method of expanding the serial port is designed to solve the problem of insufficient resources of the host serial port encountered in practical applications. At present, this method has been successfully applied to the three-meter remote transmission system. In the process of solving this problem, this article also compares other solutions.

The Links:   KCS057QV1BH-G20 7MBI75N-060-10