1 Introduction

With the increasing requirements of modern industrial production and scientific research on data acquisition system, transmission speed, error correction ability and simplicity of operation and installation have always been concerned by people when collecting data, which makes data communication technology inevitably become the key technology, What kind of interface the data acquisition system uses for data communication is one of the important factors affecting the overall efficiency of the system. USB (Universal Serial Bus) bus interface technology has gradually become the development trend of modern data transmission because of its advantages of high speed, easy equipment installation and configuration, easy expansion, bus power supply and flexible use [1-5].

This paper presents a USB interface design scheme of data acquisition system based on C8051F320, completes the hardware circuit design and software program development of USB interface, and applies it to the warehouse video monitoring system to realize fast and convenient data acquisition and transmission.

2 principle of C8051F320 single chip microcomputer

2.1 main features of C8051F320

C8051F320 is one of the C8051F series microcontrollers launched by Cygnal company of the United States, which is used for USB devices. 2304 byte ram and 16K byte flash memory are integrated in the device. Because the chip can be designed without any external components (including resistance and crystal oscillator), it is an ideal choice for small USB applications. Compared with other similar USB products, C8051F320 mainly has the following characteristics:

USB interface design of data acquisition system based on C8051F series MCU

① Meet USB2.0 protocol;

② It can operate at full speed (12 Mbps) or low speed (1.5 Mbps);

③ Integrated with a clock source, no external crystal oscillator can be used for full speed or low-speed transmission;

④ Support 8 flexible and universal USB endpoints;

⑤ Built in a 1K USB special buffer memory;

⑥ Integrated with a USB receiver, no external resistance is required.

⑦ With high speed enhanced 8051   MCU   The MCU core adopts pipelined instruction structure, 70% of the instruction execution time is one or two system clock cycles, and the processing speed can reach 25mips (when the clock frequency is 25MHz).

In addition, C8051F320 has many other features, such as supporting in system programming (ISP), with programmable digital I / O and digital cross switch, and providing full speed and non-invasive on-chip debugging circuits.

2.2 pin and package of C8051F320

The pin arrangement of C8051F320 is shown in Figure 1, and the package is tqfp-32. VDD is digital power supply; GND is analog ground; Register is the input of 5V calibrator; Rst / c2ck is the reset pin of the equipment or the clock signal of EC2 debugging interface; P3.0/c2d is the bidirectional signal pin of port P3.0 or EC2 debugging interface; VBUS is the input pin of USB bus; D + is the D + of USB; D – is USB D -; P0.2/xtal1 is port 0.2 or external crystal oscillator input; P0.3/xtal2 refers to port p0.3 or external crystal oscillator output; P0.6/cnvstr is the input pin of port p0.6 or ADC0 external conversion start; P0.7/vrff is the input or output of port p0.7 or external reference power supply; P0.0, P0.1, P0.4, p0.5, P1.0 ~ P1.7, p2.0 ~ p2.7 are the corresponding port pins.

3 USB interface circuit design

3.1 USB interface hardware circuit design

Due to C8051F320   A USB receiver is integrated in the microcontroller, which is simple and easy to use. Therefore, it is relatively simple to use it to design the hardware of USB interface. It mainly includes two parts: one is the selection of power supply mode of interface conversion module, and the other is the connection of USB pin. Fig. 2 is the circuit diagram of its USB interface. The module selects the self power supply mode, and the power supply of the whole Module shown in Figure 2 comes from the external 5V power supply. The USB transceiver in C8051F320 has integrated a pull-up resistor, which can be directly connected to the USB interface without any external devices.

3.2 USB device firmware program design

USB device firmware program is a necessary part of USB device. Its main purpose is: when the USB device is connected to the host, the host can find a new device, then establish the connection and complete the data transmission task, that is, it can enable the host computer to detect and identify the USB device normally. Therefore, the purpose of this firmware design is to enable the host to identify the C8051F320 device and communicate with it correctly. At the same time, in order to achieve the maximum transmission speed on USB, C8051F320 firmware is designed as interrupt driver.

C8051F320 firmware is divided into two parts: foreground main program and background interrupt service program (ISR). In the USB firmware program, the most important work is the definition of USB descriptor and the processing of USB transmission interrupt.

USB descriptor is a set of fixed structure description language defined by USB protocol to describe device functions and attributes.

Descriptors in USB2.0 include 8 standard descriptors such as device descriptor, configuration descriptor, interface descriptor and endpoint descriptor, as well as some other non-standard descriptors. The USB host completes the identification and configuration of the device type through the USB descriptor, and the client driver uses this information to correctly access and communicate with the device. In addition to endpoint 0, endpoint 1 and endpoint 2 are also used in the configuration of C8051F320. Their descriptors are shown in Table 1.

The processing of USB transmission interrupt is also an important part. The processing of transmission interrupt is completed by ISR and foreground main program. The data exchange between the two parts is realized through event flag and data buffer [6]. When the USB engine of C8051F320 receives a data packet from the host, it will generate an interrupt request. C8051F320 immediately responds to the interrupt and determines the interrupt source by reading the three interrupt registers cmint, in1int and out1int of the USB function controller (USB reset interrupt, endpoint 0 interrupt, endpoint 1 input interrupt and endpoint 2 output interrupt), Then jump into the corresponding processing module according to different interrupt sources for different interrupt processing, and return after processing. Among them, endpoint 0 is the default control transmission endpoint that every USB device must support. It is mainly used for the configuration of USB devices by the host, the acquisition of status information and the correction of device errors. Its interrupt processing module is composed of control output and control input. Each transmission starts with the setting transaction, then jumps into the corresponding processing module according to different interrupt sources of the setting transaction data for different interrupt processing, and returns after processing. At the same time, in ISR, the firmware moves the data packet from the USB engine internal buffer of C8051F320 to a custom data buffer, and then requests to clear its internal buffer so that it can continue to receive new data packets. Then return to the main loop, check whether there is new data in the custom buffer, and start other tasks. Due to this structure, the main loop only checks the new data to be processed in the user-defined buffer, focusing on the processing of new data, and ISR can also transmit data at the maximum speed. In this way, the USB operation of the program is simpler and convenient for program maintenance. The control transmission program flow of the main program and endpoint 0 are shown in Fig. 3 and Fig. 4 respectively. The program flow of endpoint 1 and endpoint 2 is similar.

4 data reception and display

After installing the driver based on C8051F320 USB device in the host (which can be downloaded on Xinhua dragon website), the device will be defaulted to be a serial port of the host. Therefore, it can be treated as a virtual serial port in the processing of the host. Reading its data is as convenient as reading serial port data, and a fast communication platform can be established soon.

The host software is developed by VC + +, and the serial communication part is written directly by API function. It provides a method for applications to send and receive data through serial interface. The host software uses API file functions to control serial communication. Refer to MSDN for specific functions and usage.

5 Conclusion

Based on the characteristics of C8051F320, such as high speed, strong processing capacity and simple structure, this paper designs a USB interface scheme of data acquisition system based on C8051F320, gives the specific design method of USB interface circuit, and develops the data and display of the host. The designed USB interface is applied to the warehouse video monitoring system, which can realize fast and convenient data transmission, and the data communication can reach the transmission rate of megabytes, meeting the requirements of real-time and fast data transmission.

Leave a Reply

Your email address will not be published. Required fields are marked *