USB (Universal Serial Bus) interface is a new interface technology used in the PC field in recent years. It is based on a single bus interface technology to meet the needs of various application fields; its plug-and-play, hot-swap support, easy expansion and other features greatly facilitate user use and have gradually become the development trend of modern data transmission.
The traditional steps to develop USB application systems are to first develop LJSB drivers using Windows DDK (Device Driver Development Kit) or third-party development tools (such as DriverSt LJdic), then write DLLs (Dynamic Link Libraries) using Visual C++, and finally call DLLs to develop applications. Obviously, this is difficult for people who are not familiar with Windows programming, not to mention that the development of USB drivers is very difficult. This article introduces a simple and fast method for developing USB interface application systems. It directly develops applications that can drive the user's USB system through NI-VISA in the LabVIEW environment, completely avoiding the complexity of developing USB drivers in the past and greatly shortening the development cycle.
1 Introduction to N1-VISA
NI-VISA (Virtual Instrument Software Architecture, hereinafter referred to as "VISA") is a high-level application programming interface developed by National Instruments NI (National Instrument) for communicating with various instrument buses. VISA bus 1/() software is a comprehensive software package that is not restricted by platform, bus and environment. It can be used to configure, program and debug USB, GPIB, serial port, VXI, PXI and Ethernet systems. VISA is the I/O interface software of the virtual instrument system. Based on the bottom-up structural model, VISA creates a unified form of I/O control function set. On the one hand, for beginners or designers of simple tasks, VISA provides a simple and easy-to-use control function set, which is quite simple in application form; on the other hand, for the builders of complex systems, VISA provides very powerful instrument control functions and resource management.
2 LabVIEW and its conditions for calling VISA
LabVIEW (Laboratory Virtual Instrument Engineering Workbench) is a programming language based on graphical programs developed by NI. Users write programs by creating and calling subroutines, making the created programs modular, and the programming is simple and intuitive. A LabVIEW program is divided into three parts: the front panel, the block diagram program, and the icon/wiring port. The front panel is used to simulate the front panel of a real instrument; the block diagram program uses graphical language to control the control objects on the front panel (divided into control quantities and indication quantities); the icon/wiring port is used to define the LabVlEW program as a subroutine, thereby realizing modular programming.
When performing USB communication, VISA provides two types of functions for LabVIEW to call: USB INSTR devices and USB RAW devices. USB INSTR devices are USB devices that comply with the USBTMC protocol and can be controlled by using USB INSTR class functions. There is no need to configure NI-VISA for communication. USB RAW devices refer to any USB devices other than instruments that clearly comply with the USBTMC specification. NI-VISA must be configured for communication.
(1) Steps to configure NI-VISA
①Use the Driver Development wizard to create an INF document;
②Install the INF file and install the USB device that uses the INF file
③ Use NI-VISA Interactive Control to test the device to confirm that the USB device has been installed correctly and obtain the property values of the USB device.
For detailed procedures, please refer to the free document "Using NI-VISA to Control USB Devices" on the NI official website.
(2) VI subnodes in the LabVIEW template that work with NI-VISA
ViOpen, opens and specifies the connection of the device with VISA resource name.
ViProperty, the property subnode of the VISA device, can set the endpoint or transmission mode.
ViWrite, writes data to the device specified by VISA resource name.
ViRead, reads data from the device specified by VISA resource name.
ViClose, ends the device reading and writing and closes the connection with the specified device.
(3) USB RAW device read and write operation sequence
The read and write sequence of USB RAW devices is shown in Figure 1.
3 System Hardware Structure
The system is based on Philips' enhanced 80C51 microcontroller, as shown in Figure 2. This is a multi-point temperature acquisition system. The core device is the P89C52 with 8 KB non-volatile Flash program memory, which is fully compatible with the standard 80C51. The USB communication control chip uses Philips' PDIUSBD12 chip (abbreviated as "D12"). It is a relatively new dedicated USB communication control chip that complies with the USB1.1 version specification of the universal serial bus. It integrates a serial interface engine SIE, a 320-byte FIFO memory, a transceiver and a voltage regulator. The front-end temperature sensor uses the DS18B20 produced by Dallas. It is a one-line digital temperature sensor that directly outputs digital quantities to the microprocessor, which can save a lot of leads and signal conditioning circuits. There is a photolithographic ROM inside the DS18B20. This ROM stores a 64-bit serial number. It can be regarded as the address sequence code of the DS18B20, so multiple temperature sensors can be hung on one bus and occupy one I/O line of the microcontroller to realize the interface. On the premise of improving the I/O line driving capability of the microcontroller, the number of temperature points to be detected can be expanded arbitrarily in theory.
There are two ways to interface D12 with the microcontroller: multiple address/data bus mode and single address/data bus mode. The single address/data bus mode is selected here, so the ALE of D12 is connected to a low level, and the A0 pin is connected to the port P3.3 of P89C52X2. This port controls the command and data status of D12: A0=1, indicating that there is a command on the data bus; A0=0, indicating that there is data on the data bus. The data bus of D12 is directly connected to the P0 port, and the interrupt pin INT_N of D12 is connected to: INTO of P89C52X2. When one of the external interrupts of D12 is 1, INT_N outputs a low level, triggering the external interrupt of P89C52X2. Because the system does not use DMA, the DMACK_N pin of D12 is connected to a high level, and the EOT_N pin is connected to the +5V of USB through a resistor to correctly detect the USB connection; a pull-up resistor is added to the INT_N pin. Because D12 has an on-chip power-on reset circuit, the RESET_N pin is directly connected to the power pin VCC. The temperature sensor DS18B20 works in external power mode, and the DQ pin is directly connected to P1.O of P89C52X2.
[page]
3.1 System Working Principle
According to the USB protocol, any transmission is initiated by the host, and the foreground work of the MCU is to wait. The host PC must first send a token packet to the USB. When D12 receives the token packet, it sends an interrupt to the MCU, and the MCU enters the interrupt service program. First, read the interrupt register of D12, determine the type of the LJSB token packet, and then perform the corresponding operation. Therefore, the USB MCU program is mainly the writing of the interrupt service program. In the USB MCU program, the response to various token packets must be completed, mainly programming the port.
3.2 Software Design
The system firmware program is divided into two parts from the functional point of view, and the entire programming is completed in the Keil C environment.
(1) Temperature sensor DS18B20 reading program
The single-line communication function of DSL8B20 is realized by time-sharing. It has very strict timing requirements, and its operation must be carried out according to the protocol, that is, initialization → sending ROM operation command → sending memory operation command → data processing.
(2) Communication program between MCU and USB interface
This program uses endpoint 1 and endpoint 2 of D12 to transmit commands and data between the host computer and MCU P89C52. Endpoint 1 and endpoint 2 are set to mode 0 (asynchronous mode). Endpoint 1 transmits data in interrupt mode and response mode, while endpoint 2 transmits data in batch mode. Endpoint 1 receives the read command sent by the host computer, and endpoint 2 returns the read success data.
The firmware program of the system is written in a hierarchical structure. It is a building block structure, as shown in Figure 3.
①Hardware abstraction layer: operates the I/O port, data bus and other hardware interfaces of the microcontroller.
②PDIUSBDl2 command interface: module subroutine set for operating D12 devices
③Interrupt service program: When D12 sends an interrupt request to the microcontroller, read the data transmitted by the D12 interrupt, set the event flag "EPPFIAGS" and the Setup package data buffer "CONROL_XFER" and transmit them to the main loop program.
④Standard device request handler: processes USB standard device requests.
⑤Manufacturer request handler: processes manufacturer requests added by users.
⑥ Main program: issue USB data transfer requests, handle bus events and call user-defined function subroutines
Design of host LabVIEW application driven by NI-VISA, NI-VISA uses version 3.2 and LabVIEW uses version 7.1.
The main framework of the entire application uses a WHILE loop to perform continuous queries. In the process of programming, an event-driven mechanism similar to that in Windows programs is adopted. LabVIEW provides such a structure - event structure. The generation of each message utilizes various interface controls and is given by the Case selection structure. The program structure diagram is shown in Figure 4.
In order to explain the USB operation sequence, the event structure in Figure 4 is used as a shortcut to develop the USB driver application.
In Figure 5, the USB RAW device communication uses endpoint 1 to receive the host computer operation command in interrupt transmission mode, and the protocol can be agreed upon by itself. Endpoint 2 sends temperature data back to the host computer in batch transmission mode. The endpoint number "130" is the decimal number corresponding to the hexadecimal number "0082", which indicates the batch input of endpoint 2; and the endpoint number "1" is the decimal number corresponding to the hexadecimal number "0001", which indicates the interrupt output of endpoint 1.
Because NI-VISA 3.2 does not support the USB attribute "interrupt out", in order to implement the interrupt output of USB endpoint 1, the USB attribute "bulk out pipe" and the "VI Write" node are combined here to implement the interrupt output of endpoint 1. From NI-VISA 3.3 onwards, the "interrupt out" attribute can be used directly to achieve this.
Conclusion
Practice has proved that the design of USB interface application system based on NI-VISA driver is very easy, with low development difficulty and low requirements for developers; the developed system is stable and reliable, and even people who are not familiar with Windows programming can develop USB application system. It provides another shortcut to develop USB driver application.
References:
[1]. 80C51 datasheet http://www.dzsc.com/datasheet/80C51_103447.html.
[2]. ROM datasheet http://www.dzsc.com/datasheet/ROM_1188413.html.
[3]. DS18B20 datasheet http://www.dzsc.com/datasheet/DS18B20_819975.html.
[4]. P89C52X2 datasheet http://www.dzsc.com/datasheet/P89C52X2_538908.html.
Previous article:Sound energy design based on LabVIEW development platform
Next article:Multi-channel instrument temperature measurement and control system based on LabVIEW
Recommended ReadingLatest update time:2024-11-16 13:38
- Popular Resources
- Popular amplifiers
- 100 Examples of Microcontroller C Language Applications (with CD-ROM, 3rd Edition) (Wang Huiliang, Wang Dongfeng, Dong Guanqiang)
- Arduino Nano collects temperature and humidity data through LabVIEW and DHT11
- Modern Testing Technology and System Integration (Liu Junhua)
- Computer Control System Analysis, Design and Implementation Technology (Edited by Li Dongsheng, Zhu Wenxing, Gao Rui)
- Keysight Technologies Helps Samsung Electronics Successfully Validate FiRa® 2.0 Safe Distance Measurement Test Case
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- Seizing the Opportunities in the Chinese Application Market: NI's Challenges and Answers
- Tektronix Launches Breakthrough Power Measurement Tools to Accelerate Innovation as Global Electrification Accelerates
- Not all oscilloscopes are created equal: Why ADCs and low noise floor matter
- Enable TekHSI high-speed interface function to accelerate the remote transmission of waveform data
- How to measure the quality of soft start thyristor
- How to use a multimeter to judge whether a soft starter is good or bad
- What are the advantages and disadvantages of non-contact temperature sensors?
- 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
- Open and recover data from a hard drive made in the US
- SensorTile.box Trial (4) A Preliminary Study on the Programming Mode
- The PCBs drawn by AD always give me round holes.
- [2022 Digi-Key Innovation Design Competition] [Portable Environmental Status Detector] Material Unboxing - ESP32-S2-Kaluga-1
- Qorvo's Programmable Power
- Bluetooth chip CC2541 problem, about RSSI indicator
- Vehicle Occupant Detection Reference Design
- TMS320VC33 Study Notes Development Environment
- ST bluDFU, can you provide the source code of this upgrade app?
- What benefits can 5G bring? Welcome to leave a message and give points for good posts