Design of USB interface for data acquisition system based on C8051F320

Publisher:breakthrough3Latest update time:2009-10-19 Source: 微计算机信息Keywords:C8051F320 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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.

Pinout of C8051F320

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.

USB interface connection circuit diagram

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.

Descriptors

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.

The main program controls the transmission program flow

Endpoint 0 control transfer program flow

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.

System structure diagram

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.

Keywords:C8051F320 Reference address:Design of USB interface for data acquisition system based on C8051F320

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

Design of low-cost ECG monitoring system based on C8051F320 microcontroller
1 Introduction Virtual medical instruments make full use of the rich software and hardware resources of computers. Only a small number of special software and hardware modules are added to realize all the functions of traditional instruments and some functions that traditional instruments cannot realize, wh
[Microcontroller]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号