USB Transfer Tutorial
There are two main categories of USB communication; the first is the exchange used in enumerating the device, and after that, secondly, the transfer used by applications that perform the device’s purpose. During this start up phase of USB, called enumeration, the host first finds out details about the USB device and prepares it for the later exchanging of data. Then application data transfer happens when the host transfers back and forth the data that you are going to use the device for. As an example, lets consider a keyboard device; the running host application gets the sending of keypress data to then display this character on the screen in your word processor. This all happens after the enumeration phase where the host figures out that it is a keyboard and it gets character data.
So, during the enumeration process, if the device has a microcontroller, its programming has to check for requests from the host. The device then has to identify each request and send back the requested information plus do other things asked by the host as requests. For example if you have a joystick, the host would ask how many buttons or knobs exist and the device would send that back.
Now on PC’s, Windows does the enumeration, so the user doesn’t have do any programming. But to finish up the enumeration when you first attach the device, Windows has to find a particular INF file that indentifies the file name and location of its USB device driver. As you probably know, if the required files are found, the programming of the device’s microcontroller functions correctly, and the enumeration process is done seamlessly behind the users back with out them having to do anything.
This is why a lot of times you have warning messages on packages of new hardware asking you to load from the CD first the USB device drivers before inserting the device. What happens otherwise is Windows goes out and gets a default driver for your device that maybe is just a minimal functioning one rather than the enhanced one written by the manufacturer that you really need.
After the host has transferred back and forth the device enumeration details with the USB device and a device driver is assigned to it and loaded, the application can now start to communicate. The programs running on the host can use standard Windows API calls or other popular Windows components to read and write to the device ultimately using the device driver.
Looking at the device’s microcontroller programming, transferring data usually involves either placing data to send in the controller’s transmit buffer or retrieving received data from its receive buffer. The controller has flags that tell when either type of transfer has completed ensuring that everything is ready for the next transfer. The microcontroller also has to be programmed to handle exceptional conditions such as error handling and other events like the low power sleep mode.
There are four types of data transfers, control, interrupt, bulk, and isochronous. Each type of USB device class such as keyboard, external hard drive, or video capture device uses these data transfers types to achieve different needed results. A time critical video device would use isochronous transfers with their fast delivery and data drop out if necessary. While a hard drive storage class uses bulk just to get the data transferred without worrying about time but verifying that things got transferred ok. A keyboard or mouse uses the interrupt transfer for small bits of data with less critical timing as that of say a USB video device.
Related posts:
Hey – I found your site by mistake. I was looking in Google for PDF software that I had already purchased when I came upon your site, I must say your site is pretty cool I just love the theme, its amazing!. I don’t have the time this minute to fully read your site but I have bookmarked it and also signed up for your RSS feed. I’ll back in a day or two. thanks for a awesome site.
great tutorial well tutorial are always worth reading enhance your knowledge.really appreciate your way of explanation.very well written very distinctive and to the point great work.