1 Introduction
As modern industrial production and scientific research place increasing demands on data acquisition systems, transmission speed, error correction capability, and ease of operation and installation have always been issues that people are concerned about when collecting data. This has made data communication technology inevitably become a key technology, and the interface used by the data acquisition system 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 due to its advantages such as fast speed, easy device installation and configuration, easy expansion, bus power supply, and flexible use [1-5].
This paper presents a USB interface design for a data acquisition system based on C8051F320, completes the USB interface hardware circuit design and software program development, and applies it to the warehouse video surveillance system to achieve fast and convenient data acquisition and transmission.
2 C8051F320 MCU Principle
2.1 Main Features of C8051F320
C8051F320 is a small MCU for USB devices from the C8051F series of MCUs launched by Cygnal Corporation of the United States. The device integrates 2304 Byte RAM and 16K Byte Flash memory. Since the chip does not require any external components (including resistors and crystal oscillators) when designing, it is an ideal choice for small USB applications. Compared with other similar USB products, C8051F320 has the following main features:
① Meet USB2.0 protocol;
② Can run at full speed (12 Mbps) or low speed (1.5 Mbps);
③ An integrated clock source is available, which eliminates the need for an external crystal oscillator for full-speed or low-speed transmission;
④ Support 8 flexible and universal USB endpoints;
⑤ Built-in 1K USB dedicated buffer memory;
⑥ Integrated a USB receiver, no external resistor required.
⑦ It has a high-speed enhanced 8051 MCU core, which adopts a pipelined instruction structure. 70% of the instructions are executed in one or two system clock cycles, and the processing speed can reach 25MIPS (when the clock frequency is 25MHz).
In addition, the C8051F320 has many other features, such as support for in-system programming (ISP), with programmable digital I/O and digital cross switches, providing full-speed, non-intrusive in-system on-chip debugging circuits, etc.
2.2 Pinout and Package of C8051F320
The pin arrangement of C8051F320 is shown in Figure 1, and the package is TQFP-32. Among them, VDD is the digital power supply; GND is the analog ground; REGIN is the input terminal of the 5V calibrator; RST/C2CK is the reset pin of the device or the clock signal of the EC2 debug interface; P3.0/C2D is the bidirectional signal pin of port P3.0 or EC2 debug interface; VBUS is the USB bus input pin; D+ is the D+ of USB; D- is the D- of USB; P0.2/XTAL1 is the input of port 0.2 or external crystal oscillator; P0.3/XTAL2 is the output of port P0.3 or external crystal oscillator; P0.6/CNVSTR is the input pin of port P0.6 or ADC0 external conversion start; P0.7/VRFF is the input or output terminal 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 all corresponding port pins.
3 USB interface circuit design
3.1 USB interface hardware circuit design
Since the C8051F320 microcontroller has an integrated USB receiver, it is easy to use, so the hardware design of the USB interface is relatively simple. It mainly includes two parts: one is the selection of the power supply mode of the interface conversion module, and the other is the connection of the USB pin. Figure 2 is the circuit diagram of its USB interface. The module selects the self-powered mode. The power supply of the entire module shown in Figure 2 comes from an external 5V power supply. The USB transceiver in the C8051F320 has integrated pull-up resistors, and can be directly connected to the USB interface without any external devices.
Figure 2 USB interface connection circuit diagram
3.2 USB Device Firmware Programming
The USB device firmware program is a part that must be implemented by the USB device. Its main purpose is: when the USB device is connected to the host, the host can discover the new device, then establish a connection and complete the data transmission task, that is, to 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 the USB, the C8051F320 firmware is designed to be interrupt-driven.
The C8051F320 firmware is divided into two parts: the foreground main program and the background interrupt service routine (ISR). In the USB firmware program, the most important work is the definition of USB descriptors and the processing of USB transmission interrupts.
USB descriptors are a set of fixed-structure description languages defined by the USB protocol to describe device functions and properties.
The descriptors in USB2.0 include 8 standard descriptors such as device descriptors, configuration descriptors, interface descriptors, endpoint descriptors, and some other non-standard descriptors. The USB host completes the identification and configuration of the device type through the USB descriptors, and the client driver uses this information to correctly access the device and communicate with it. In this article, 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 interrupts is also an important part. The processing of transmission interrupts is completed by the ISR and the foreground main program. The data exchange between these two parts is realized through event flags and data buffers [6]. When the USB engine of C8051F320 receives a data packet from the host, an interrupt request will be generated. C8051F320 will respond to the interrupt immediately and determine the interrupt source (USB reset interrupt, endpoint 0 interrupt, endpoint 1 input interrupt, endpoint 2 output interrupt) by reading the three interrupt registers CMINT, IN1INT and OUT1INT of the USB function controller. Then, according to the different interrupt sources, it will jump into the corresponding processing module to perform 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 host to configure the USB device, obtain status information and correct device errors. Its interrupt processing module consists of two parts: control output and control input. Each transmission starts with setting the transaction first, and then jumps into the corresponding processing module according to the different interrupt sources of the setting transaction data to perform different interrupt processing and return after processing. At the same time, in the ISR, the firmware moves the data packet from the internal buffer of the USB engine 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 it returns to the main loop, checks whether there is new data in the custom buffer and starts other tasks. Due to this structure, the main loop only needs to check the new data that needs to be processed in the custom buffer, focusing on the processing of new data, and the ISR can also transmit data at the maximum speed. In this way, the program's operation of USB is simpler and it is also convenient for program maintenance. The control transmission program flow of the main program and endpoint 0 is shown in Figure 3 and Figure 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 from Xinhualong website), the device will be set as a serial port of the host by default. Therefore, it can be treated as a virtual serial port in the host processing. Reading its data is as convenient as reading serial port data, and a fast communication platform can be established quickly.
The host software is developed using VC++, and the serial communication part is written directly using API functions. It provides the application with a method to send and receive data through the serial interface. The host software uses API file functions to control serial port communication. For specific functions and usage, please refer to MSDN.
The USB interface circuit based on C8051F320 is applied to the warehouse video surveillance system, and its system structure block diagram is shown in Figure 5.
5 Conclusion
This paper uses the characteristics of C8051F320, such as fast speed, strong processing ability, and simple structure, to design a USB interface solution for data acquisition system based on C8051F320, gives the specific design method of USB interface circuit, and develops the data and display of the host. Applying the designed USB interface to the warehouse video surveillance system can achieve fast and convenient data transmission, and the data communication can reach a transmission rate of megabytes, meeting the requirements of real-time and fast data transmission.
Previous article:Development of high-precision weighing system based on AT89S32 single-chip microcomputer
Next article:Design of Wireless ECG Monitoring System Based on C8051 Single Chip Microcomputer
Recommended ReadingLatest update time:2024-11-16 21:34
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- [NUCLEO-L552ZE review] + Summary of voice control home appliance experiment
- ST NUCLEO-H743ZI Review Summary
- Animation showing the working principle of capacitive sensors and capacitive headphones
- 【New Year's Festival Competition】+Flying Yingge Dance
- MSP430f5529 car source code
- 【EasyARM-RT1052 Review】+ Transplantation and use of Fatfs file system based on SD card
- Theoretical basis of the movie "The Wandering Earth"
- Satellite Internet in One Picture
- cc254x cc2640 WeChat access airsync-broadcast data
- Summary of issues in design and installation of grounding devices