51 microcontroller controls the USB host bottom driver of SL811HS

Publisher:WhisperingWishLatest update time:2006-07-18 Source: 电子设计应用Keywords:register Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Introduction

Devices based on USB interface are easy to use and cost-effective, so they have been widely used in people's work and life, such as U disk, mobile hard disk, optical drive, USB camera, USB mouse and keyboard, etc. At the same time, the 51 series of microcontrollers are known for their Mature technology and high cost performance have attracted a large number of domestic users and are widely used in the fields of measurement, control and automation. Therefore, if a USB host interface is added to the 51 microcontroller system to control USB slave devices, the microcontroller system can make full use of it. Various existing USB slave devices greatly expand the functions of the microcontroller system.

This design implements the addition of USB host function to the 51 microcontroller system, using the solution of connecting an ordinary 51 microcontroller to a dedicated USB interface chip. Although this solution will limit the system transmission speed and lack stability, the design of this solution It is highly flexible and easy to transplant, providing broad prospects for the development of low-cost products. The 51 microcontroller used in the design is the AT89S52 chip of Atmel Company. The expansion of the USB host function is achieved through the external dedicated USB interface chip SL811HS. The USB interface of CYPRESS Company The chip SL811HS can work in host or slave mode and supports USB1.1 full-speed and low-speed data transmission. When working in host mode, SL811HS can automatically detect the plugging and unplugging actions of peripherals and can follow the requirements of the external processor (such as a microcontroller) Automatically integrate data into USB protocol data packets for data transmission.

This article will introduce the hardware equipment and the writing of the bottom-level driver controlled by the microcontroller AT89S52 to control the SL811HS, focusing on the design of the bottom-level driver.

The hardware schematic diagram of the hardware design

system is shown in Figure 1. The power supply voltage of AT89S52 is 5V and that of SL811HS is 3.3V. Although the power supply voltages are different, according to the analysis of the signal noise tolerance parameters of the chip pins, the difference between AT89S52 and SL811HS is The pins can be connected directly without level translation or buffering.

Software design

USB host driver is a combination of high-level and low-level subroutines. The process of realizing USB transmission and control is the process of higher-level subroutines calling lower-level subroutines. When writing the USB host driver, you can proceed from low-level to high-level. proceed in layers.

Taking the operation of a USB host to enumerate slave devices as an example, the hierarchical relationship between subroutines at each level required to implement this function is shown in Table 1. This article will introduce the implementation of several subroutines at the lower level, including reading and writing the internal registers of SL811HS , the implementation of transmission transactions, device plugging and unplugging detection, reset, etc. Among them, the implementation of transmission transactions is the key and difficult point, and it is also the focus of this article.

The microcontroller reads and writes
the internal registers of SL811HS
. The subroutine of reading and writing the internal registers of SL811HS is the lowest level subroutine. Various operations performed by the system are mainly realized by calling these subroutines to read and write the internal registers of SL811HS. For example, by reading the internal registers of SL811HS The status register obtains the status information of SL811HS to implement device plugging and unplugging detection, device speed detection, etc. By writing control bytes to the relevant control register of SL811HS, operations such as USB bus reset and USB data transmission can be achieved.
SL811HS internal register
From the perspective of programming structure, the SL811HS internal register has a total of 256 units. Each unit is a byte. The first 16 units with addresses [00H]-[0FH] are the status register or control of SL811HS. registers (collectively referred to as special registers), and the rest are data buffer registers. Table 2 lists the names and main functional meanings of the 16 special registers.
The realization of the microcontroller reading and writing
the internal registers
of SL811HS is based on the read and write control signal timing diagram of SL811HS. The subroutine for the microcontroller to read and write the internal registers of SL811HS is written so that each control pin can give signal pulses that meet the requirements according to the specified timing. In this program, the size of the microcontroller instruction cycle will directly affect the retention time and timing relationship of the output signal.
Initialization
The initialization operations mainly include SL811HS chip reset, USB bus reset, device insertion and removal detection, device USB data transmission speed detection, etc. Through these initialization operations, SL811HS will establish a bottom-level protocol connection relationship between the USB host and the slave, which will provide the basis for subsequent Be prepared for data communications.
SL811HS chip reset The reset
of the USB interface chip SL811HS is to reset the status of the chip, including resetting the internal register value of the chip. To achieve this operation, you do not need to read or write the internal register of the interface chip. You only need to input a A valid reset pulse is sufficient.
USB bus reset.
According to the USB protocol, the USB bus reset refers to outputting the SE0 state on the USB data line and maintaining it for more than 10ms. The slave device connected to the USB bus will perform its own reset operation after receiving this reset signal to provide the next USB Prepare for data transmission. By setting bits 4 and 3 of the CtrlReg[05H] register of the interface chip to logic "01" and keeping them for 10ms, and then returning them to logic "00", you can allow the interface chip to generate USB Bus reset signal.
Device plugging and unplugging detection and device speed detection
are on the physical layer of the USB protocol. Whether the USB slave device is connected to the USB bus is known by detecting the voltage of the bus. According to the level of the voltage, the devices on the USB bus can also be obtained. Supported speeds (for example, in the USB1.1 protocol, there are low speed and full speed). The USB host interface chip SL811HS reflects the voltage detection results of this physical layer to the value of the status register. By reading the values ​​of these status registers, the device speed of the current device plug-in and unplug status can be known.
In addition to the above three items, the initialization operations performed by the USB host also include the setting of frame start packet activation/disablement, frame synchronization setting, frame timing initial value setting, etc., which are all performed by reading and writing the special register of the interface chip. realized.
Implementation of transmission transactions
According to the USB1.1 protocol, a transmission transaction generally includes the transmission of three packets (Packet), namely the transmission of token packet (Token Packet), respectively, token packet (Token Packet) and data packet (Data Packet) and handshake packet. There are four USB data transfer methods, namely Control Transfer, Isochronous Transfer, Interrupt Transfer and Bulk Transfer. Among them, the control transmission method consists of at least two transmission transactions, and the other three transmission methods each consist of one transmission transaction. It can be seen that the transmission transaction is crucial in USB transmission.
A typical transmission transaction contains the transmission of 3 packets. The continuous data flow of 3 packets is shown in Table 3.

When using SL811HS to design a USB host system, the user only needs to let the microcontroller set several related special registers inside SL11HS, and then enable the transmission transaction start bit (set to logic "1"), so that the interface chip can automatically complete these three tasks. For the sending and receiving of packets, in the example shown in Table 3, the nth packet (mark packet) and the n+2nd packet (handshake packet) are both sent from the host to the slave, and the n+1th packet (data packet) It is sent from the slave to the host. This transmission direction and the transmission direction of the n+2th packet are determined by the value of the identification field in the marked packet. The rules can be referred to the USB protocol.

If the data packet of the transmission transaction is sent from the slave to the host, the transmission transaction belongs to the input type and is called an input transmission transaction. Otherwise, it is called an output transmission transaction. It can be seen that the example in Table 3 is an input transmission transaction. For an input For transmission transactions, the microcontroller can determine the value of the packet fields by setting the internal special register of SL811HS: the identification field, address field or endpoint field in the marked packet, and the identification field in the data packet. In the input transmission transaction, although the data packet is not sent by the host, the reason why the microcontroller is still required to set the register related to the identification field of the data packet is because the host will only recognize data whose identification field matches the set value in this transmission transaction. Bag. The rest, such as other fields in the marked packet and the contents of the handshake packet, are automatically generated by SL811HS according to the situation.

After the host interface chip SL811HS completes an input transmission transaction, if the transmission is successful, the microcontroller can read the data sent from the slave from the data buffer register of SL811HS. Here, the first address of the data buffer is preset by the microcontroller through the control register Specified.

For output transmission transactions, the microcontroller also needs to set related registers to determine the identification field, address field, endpoint field and identification field of the data packet, as well as the first address of the buffer to store the sent data, and the data in this buffer It is also written by the microcontroller.

Specifically, the steps that the microcontroller needs to perform when controlling the USB host interface chip to perform a transmission transaction are as follows:

First, if it is an output transmission transaction, the data to be sent to the slave in the data packet needs to be stored in the data buffer of SL811HS District.

Secondly, make relevant transmission preparations, that is, set the four special registers in the interface chip. The names of these four registers and their roles in the transmission transaction are listed in the first four items of Table 4.

Third, start the transmission transaction: Set bit 0 (that is, the transmission transaction start bit) of the register EP0Control[00H] or EP1Control[08H] to logic "1" to start the transmission transaction. But before that, other bits in this register must be set (or set at the same time as the start bit). The packet fields related to this register are listed in the last item in Table 4.

Fourth, the microcontroller reads the value of the register EP0Status (03H] or EP1Status[0BH] to know the completion of this transaction transmission.

Finally, if the transmission is successful and the transmission transaction is of an input nature, the microcontroller can read the data buffer area to obtain the data sent from the slave.

Conclusion

In the bottom driver of the 51 microcontroller controlling the USB interface chip SL811HS, the subroutine for reading and writing the internal registers of SL811HS is the bottom layer, and various lower-layer operations of USB transmission, such as bus reset , plugging and unplugging detection, speed detection and transmission transactions are mainly realized by reading and writing the internal special registers of SL811HS. Among them, the realization of transmission transactions directly involves the reading and writing of 5 special registers.
In the underlying driver foundation described in this article By adding relevant high-level programs, the 51 microcontroller system can realize the enumeration control of various USB slave devices and the data exchange of U disks, which provides a broad application prospect for the development of the 51 microcontroller system. The USB host design of other platforms has certain reference value.
Keywords:register Reference address:51 microcontroller controls the USB host bottom driver of SL811HS

Previous article:AT89C51/55 constitutes an automatic temperature and humidity monitoring system
Next article:51 microcontroller controls the USB host bottom driver of SL811HS

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号