“Introduce a USB interface design based on single-chip microcomputer and USB service chip PDIUSBD12. This interface is used in the embedded fingerprint identification system to upload and download the user fingerprint database between the embedded system and the computer. The hardware design of the USB interface and the realization of the firmware program are introduced in detail.
Introduce a USB interface design based on single-chip microcomputer and USB service chip PDIUSBD12. This interface is used in the embedded fingerprint identification system to upload and download the user fingerprint database between the embedded system and the computer. The hardware design of the USB interface and the realization of the firmware program are introduced in detail.
In fingerprint automatic identification systems, embedded systems have been used more and more widely due to the advantages of low Power consumption, small device size, and high security. Universal Serial Bus (USB) is a microcomputer bus interface specification jointly developed by Inter, Microsoft, IBM and NEC. It has a high transmission rate (USB 1.1 supports a maximum transmission speed of 12Mb/s, while USB 2.0 has the highest transmission speed It can reach 480Mb/s), supports plug and play, takes up less system resources, and has strong scalability. In the application of embedded system, communication with PC is almost inevitable. Due to the requirement of communication speed and the high-speed development of computer hardware, the traditional RS232 interface has become more and more unable to meet the needs of users. Therefore, in the embedded system, the USB interface The realization of it is imperative.
1. Embedded fingerprint automatic identification system
The embedded fingerprint automatic identification system introduced in this article uses DSP and single-chip microcomputer to work together to realize automatic fingerprint identification and user service system. Among them, the one-chip computer selects the P89C52 of Philps Company, and the DSP processor selects the TMS320C5416 of TI Company. The single-chip microcomputer has the characteristics of strong system control ability, simple structure, convenient expansion, etc., which is suitable as the control core of the system; and the enhanced Harvard structure, multi-stage pipeline, multi-processing unit and special instructions (multiply-add instructions) adopted by DSP make DSP has powerful data processing capabilities, and TMS320C5416 supports a clock frequency of up to 160MHz. Based on its powerful data processing capabilities and high operating speed, it is used as the algorithm core processor of the system. The control module with the single-chip microcomputer as the core mainly completes the user service system and system communication interface, and the algorithm module with the DSP as the coprocessor completes the fingerprint collection and processing. The user controls the working process of the entire system through keyboard input, and understands the working status and processing results of the system through the LCD. The DSP communicates with the single-chip microcomputer in interrupt mode by its HPI (host interface). The entire system communicates with the upper PC through the USB interface. Its structure is as shown in the figure. When a new user is registered in the system, the registration ID is entered through the keyboard, and then the system is controlled by the DSP to control the fingerprint sensor to collect user fingerprint data. If a valid fingerprint is collected, the fingerprint template data is obtained through DSP for fingerprint processing. The system saves the fingerprint template into the system database. If necessary, the user information and corresponding templates can also be uploaded to the PC for backup via the USB interface. When the embedded system data is lost, the backup stored in the PC can be downloaded to the system through the USB interface. The following focuses on the design of the control module and USB interface of the system.
2. System control module design
The core processor of the system control module is P89C52. Due to its limited interface, it will be very difficult to complete system control and USB interface control at the same time. In terms of system cost, development time cycle and inheritance, it is not convenient to switch to other processors, so it is necessary to consider completing multiple tasks on the basis of this processor. Judging from the characteristics of the fingerprint automatic identification system, the system needs to use the USB interface to complete the transmission of the fingerprint template and login information after the fingerprint is entered or logged in. Therefore, for the processor, the USB control and system control can be time-division multiplexed. Way to proceed. Therefore, a level conversion chip and an 8-bus transceiver are used to control the gating and flow of data to ensure that the system can work normally.
SN74ALVC164245 is a 5V～3.3V level conversion chip, which is responsible for controlling the data flow and level conversion between the microcontroller and DSP. Because the IO level of the single-chip microcomputer is 5V, and the IO level of the DSP is 3.3V, level conversion is necessary. In addition, the OE and DIR pins of SN74ALVC164245 jointly control the flow of data. When OE is high, the data on both sides of the chip are independent of each other; when OE is low, the flow of data is controlled by the state of DIR. 74HC245 is a bus transmitter, used to control the data communication between the single-chip microcomputer and the LCD control chip KS0108. Its working principle is similar to SN74ALVC164245, but there is no level conversion function. Similarly, the USB service chip enables the data line through the SUSPEND pin. When the SUSPEND pin is set high, the entire PDIUSBD12 is in a sleep state. Therefore, the single-chip microcomputer can control the data bus by controlling the state of the pins, so as to realize the time division multiplexing of the single-chip data bus.
3. System USB interface design
3.1 USB interface hardware design
The USB interface hardware is mainly centered on the interface chip PDIUSBD12, and the connection between it and the USB physical interface and the microcontroller is designed. The interface module selects the power supply mode through the jumper, which can support the USB bus power supply mode and the peripheral power supply mode at the same time, and is a full-speed USB device interface. Reliability, testability and electromagnetic compatibility are fully considered in the design process. Its interface circuit is shown as in Fig. 3.
The power supply of the interface circuit is selected by the dial switch K1. When K1 is connected to MVCC, the system is in self-powered mode; when K1 is connected to UVSB, it is in bus power mode. When the system is in self-powered mode, the system detects the existence of VUSB through the EOT_N pin, and connects a 1M? The redundant discharge resistance reduces the charge to ensure that EOT_N becomes low when the VUSB is removed, and at this time, the self-powered power supply and the USB bus can only share the ground, and the device cannot output current to the VBNS through the USB port.
In terms of control communication between the single-chip microcomputer and PDIUSBD12, the single-chip microcomputer indicates whether the transmission content on the parallel data bus P0 is a command or data through the state control of the A0 pin of the PDIUSBD12. At this time, the ALE pin used for data address bus multiplexing on PDIUSBD12 is always grounded. The interrupt pin INT_N is the key to the system. Almost all USB activities are received by PDIUSBD12 at the device interface, and then the microcontroller is notified to complete it through an interrupt. The suspend SUSPEND on PDIUSBD12 is a bidirectional pin, which ensures that the USB device can be awakened by the device master (microcontroller) and the host PC. When PDIUSBD12 is working, it will suspend the pin without detecting SOP for 3 consecutive times. Set high.
The on-chip GL_N pin of the PDIUSBD12 uses an external light-emitting diode to indicate the working status of the system. During the USB enumeration, the LED indicator flashes intermittently according to the communication status; when the PDIUSBD12 is successfully enumerated and configured, the LED indicator will always be on; then it will be connected to the PDIUSBD12 Successful transmission (with response) will turn off the LED; when in the suspended state, the LED will turn off.
The on-chip clock generation circuit uses a 6MHz crystal oscillator, matching a 22pF and a 68pF passive capacitor. The 6MHz crystal oscillator is also used to reduce the risk of EMI (electromagnetic interference effect) during the product manufacturing process, because the higher the frequency of the external circuit, the stronger the EMI effect will be, and the lower frequency is used in the off-chip circuit and carried out inside the chip. Frequency multiplication measures will not affect the processing speed of the chip, but also improve the safety of external wiring. The purpose of using two different capacitance capacitors is to make the crystal start-up quickly. After measurement, the start-up time of the crystal oscillator is about 2ms.
PDIUSBD12 can adopt 5V and 3.3V two kinds of working voltages. Since the IO voltage of the main control MCU is 5V, the working voltage of 5V is also used for PDIUSBD12. At this time, while connecting the 5V to the PDIUSBD12 VCC pin, the VOUT pin on the PDIUSBD12 should be freed and the decoupling capacitor should be connected. In addition, in order to reduce the EMI of the system, magnetic beads are added to the VBUS and ground on the input side of the USB connector, such as BLM21P in Figure 3, and capacitive coupling is used between the USB shield and the ground.
Due to the complexity of the USB communication protocol, a considerable part of the work is done by the hardware circuit, so the accuracy of the hardware circuit design is very strict. The wiring should be reasonable to minimize the influence of distributed capacitance and electromagnetic interference. The quality of the hardware circuit will directly affect Whether the data can be transmitted normally.
3.2 Development of USB device firmware program
The firmware program is mainly composed of the main program and the interrupt service program. USB device requests include standard device requests and manufacturer requests. The standard device request is used to complete the command of USB device enumeration, and the manufacturer request is the command to complete the special task according to the specific USB device. For the USB service chip PDIUSBD12 used in this article, the on-chip SIE (Serial Interface Engine) implements all the USB protocol layers and is completely implemented by hardware without the involvement of firmware. Therefore, for the USB firmware program, the USB protocol The concrete realization can be finished according to the command word provided by PDIUSBD12. The last thing left is the implementation of the program to read and write data on the hardware layer.
The work flow is roughly as follows: the main loop completes some initialization work and transfers to a loop waiting for interruption; when a transaction occurs on the USB bus, PDIUSBD12 will automatically generate a corresponding interrupt to notify the firmware program; then the firmware program transfers to the corresponding The interrupt service program handles the interrupt. The main loop determines the corresponding request response by reading the event flag and the circular data buffer set in the interrupt service program; the response program controls the PDIUSBD12 to complete the corresponding data or through the lower PDIUSBD12 command interface program. Command operation. The combination of the firmware program of the building block structure completes all USB activities of the USB interface device from initialization to data transmission.
According to the USB1.1 protocol, this paper has completed the research and development of the USB interface hardware and firmware program of the embedded fingerprint automatic identification system by its service chip PDIUSBD12 and the single-chip microcomputer P89C52, and combined the driver and application program of the upper PC to form the entire embedded system Provides a USB interface with good stability, fast transmission speed and easy to use. Achieve flexible communication between the embedded system and the PC, so that the embedded fingerprint automatic identification system has a wider range of applications.