Universal Serial Bus (USB) is the de facto interface for computer peripherals to communicate with the personal computers. The interface that saw the light of day around the mid-1990s was a joint effort of seven companies – Compaq, DEC, IBM, Intel, Microsoft, Nortel, and NEC. These companies were aiming to replace the then parallel ports and the external power chargers with a universal communication standard that could simplify data exchange and could double duty to supply power as well.Nowadays, USB is the standard and must-have interface on almost all motherboards, single board computers and the embedded microcontroller boards and almost every digital peripheral from regular computer peripherals like keyboard, mouse and joysticks to smart digital devices.
Universal Serial Bus (USB) is the de facto interface for computer peripherals to communicate with the personal computers. The interface that saw the light of day around the mid-1990s was a joint effort of seven companies – Compaq, DEC, IBM, Intel, Microsoft, Nortel, and NEC.
After discussing the features and architecture of USB, let’s move on to its protocol. A USB interface has several layers of protocol. Most of the time the lower level layers are single handled by host controller IC while the end designer needs to work on higher level layers. Every communication protocol involves the exchange of packets. Same is the case with USB. These packets encapsulate information in a standard-defined organized manner. These packets generally contain information related to- Controlling the data exchange, Data exchange in the form of actual payload, and Error detection and correction through the status check up. In USB the LSB of the packet is transmitted first. A USB packet contains different fields.
Now that we have discussed the basic details of USB including its features, architecture, and protocol, the next topic in the series is USB Descriptors. In context to USB interface, Descriptors are formatted blocks of information, through which, the host device learns about the peripheral. It helps in identifying and configuring the peripheral device.A Descriptor contains information like type of the device, Vendor ID, Compliant USB Version, number of configurations device supports, number of endpoints, etc. The USB peripheral must respond with descriptors when requested by the host. During enumeration, the host uses control transfer to request the device for descriptors.
In the previous article of this series, USB Descriptors were discussed. When a USB peripheral is connected to a host device, the host sends queries in the form of requests. The peripheral responds by sending Descriptors. The Descriptors contain the information required for identifying and configuring the peripheral device, implementing the interfaces and setting endpoints. The device descriptor is the first descriptor sent to the host and it helps in configuring the peripheral with respect to the host. The subsequent descriptors implement the functioning, the peripheral is meant for. The Control Transfer is the only transfer type which is supported even when the device is yet not configured. That is the reason, it is used for sending requests and obtaining the descriptors. The default endpoint is endpoint 0 which is bidirectional and used for control transfers.
In this series, USB requests and descriptors have been already discussed. With the knowledge of USB requests, descriptors, transfer types and transactions it is now easy to understand how data is communicated over USB interface. Another aspect of the USB communication is line states and encoding, which is generally ignored by the system designers as a USB device can be designed without knowing the Signaling and Encoding schemes. The signaling and encoding schemes are implemented at the lower levels (usually on the controller IC) and usually gets abstracted during system designing. However, understanding the terms related to bus states and encoding would help in getting comprehensive view of the USB System.
In this series, every possible detail about the USB system including its architecture, protocols, requests and descriptors as well as signaling and encoding has been already discussed. Wrapping up the series, selection of the controller chip for the development of a USB enabled device is discussed here.
In this modern world we all are aware about USB. We all connect our Pen drives, memory card and other devices using USB. But have you ever thought what is it? Here is the answer; USB is a communication protocol by which two devices communicate with each other. In the same way, microcontroller also communicates with other devices like sensors or PC by using different communication protocols like USB, UART, and I2C.UART stands for Universal Asynchronous Receiver/Transmitter. It is a type of serial communication that uses two wires, one for transmission (Tx) and one for reception (Rx).
Universal Serial Bus (USB) is now a common and vast framework for serial communication. The interface not only allows serial communication, it also works as electronic power supply. The popular AVR microcontrollers fortunately have the USB interface feature and can be programmed to build USB devices. The USB specification is long and intimidating. It can be a daunting task to write a device specific USB driver.
A Mouse is a common computer peripheral apart from the keyboard. Even the touchpad is not able to dent the popularity of mouse. Nowadays the keyboards, as well as mouse connect through the computers via USB cable or the fancier one connect to the PCs wirelessly through Bluetooth. This project is an attempt to demonstrate the functioning of a generic USB mouse. The 8-bit USB AVR – Atmega 32u4 is used as the USB device controller in the project. In order to avoid complexity, the project uses AVR based Lightweight USB Framework (LUFA) as the firmware.
In this project, a digital voltmeter will be designed which will show the voltage reading on a desktop application. The device will read analog voltage with respect to the ground, digitize the reading and send the reading to personal computer on USB interface. The device could read four different voltages in range from 0V to 5V.For this, the device will be configured as CDC Class Device. A CDC Class device has USB communication over two types of transfers – Control transfer and Bulk transfer. The control transfer will be used for enumeration of the device. After enumeration, device will use bulk transfers for sending the voltage readings to the computer.
In this project, a device will be designed which will allow controlling a servo motor from the desktop computer on USB interface. For controlling a servo motor, PWM output needs to be generated from the microcontroller. The length of the ON time of the PWM signal at the control pin of the servo determines the angle the servo should rotate.The project device receives data from the host computer on USB interface which will determine the ON time of the PWM signal and according a PWM signal will be send out to the control pin of the servo using in-built timer. For this, the device will be configured as HID Class Device again. An HID Class device has USB communication over two types of transfers – Control transfer and Interrupt transfer.
In this project, a device will be designed that will read analog data from any analog sensor and will send the digitized form of that data to a personal computer on USB interface. On PC, a desktop application will store the data in an excel spreadsheet therefore performing the data logging. For this, the device will be configured as HID Class Device again.An HID Class device has USB communication over two types of transfers – Control transfer and Interrupt transfer. The control transfer will be used for enumeration of the device. After enumeration, the analog readings will be digitized and sent to the host computer on a real-time basis using Interrupt Transfer. In this project, Accelerometer Sensor – ADXL335 will be used as analog sensor. Any other analog sensor can also be used and tested with minor modifications in this project.
In Atmega 32u4 Based USB Controlled LED Series Project, how data is communicated from computer to a generic HID device was seen. Then, in Atmega 32u4 Based LED Status Project, how microcontroller configured as generic HID device can communicate data to the computer was studied. For data transmission from computer to device, control transfer was used while for data transmission from device to computer, interrupt transfer was used.In this project, a generic HID device will be designed that will exchange data with a computer both ways. Primarily, it will receive data packets from the host computer and will use those data packets to control input/output ports of the microcontroller.
In the Atmega 32u4 Based USB Controlled LED Series Project, it was demonstrated how to use control transfer to receive data from computer to the peripheral. In this project, it will be demonstrated to transfer data from microcontroller to the host computer. For this, the device will be configured as HID Class Device again. An HID Class device has USB communication over two types of transfers – Control transfer and Interrupt transfer.When data has to be exchanged from default endpoints i.e. endpoint 0 IN and endpoint 0 OUT only, the control transfer is sufficient to perform the data communication. Usually, HID devices only use control transfer for enumerating with the host.
Throughout this USB series, different types of USB devices have been designed and developed. These devices were enumerating with the host computer and then were using Class Specific transfers for further USB communication. Like the Keyboard, Mouse and joystick devices were using interrupt transfers for their operations after enumeration.Similarly, the audio class devices were using isochronous transfers for their operations after enumeration. The CDC Class devices were using bulk transfers for their operations after enumeration. Any of these transfers (Bulk, Isochronous or Interrupt) are enabled only after the control transfer which let the device get enumerated with the host. These transfers are required when data is also sent from the device to the host computer.
External memories are frequently used to store and carry computer data. The USB flash drives are quite common nowadays. This project is an attempt to demonstrate making of USB storage devices. The project converts an external EEPROM which basically has I2C interface to an USB device. The project actually works like a protocol changer between I2C and USB standards. The external EEPROM used in the project is AT24C512 which has 512 Kb memory space.In this project a desktop application written in Python will be used to write, read and erase data from the EEPROM. The 8-bit USB AVR – Atmega 32u4 will be used as the controller chip on the device to accept control instructions from the host computer according to USB protocol and implement the data control operations on EEPROM through I2C protocol.
The music keyboard is one of the most common musical instruments. The electronic musical keyboards have been around for a long time. The electronic music keyboards synthesize musical sounds electronically according to MIDI (Musical Instrument Digital Interface) standards. Fortunately, the USB protocol does have provision to implement the MIDI standard under Audio Class Devices. The USB protocol has the MIDI subclass under the Audio Class 1.0. In this project, the device designed is based on the MIDI subclass and it transmits the MIDI Data Packets using Audio Class of the USB protocol.On any musical keyboard, there are physical keys pressing which specific musical notes having predetermined pitch and volume are generated. Any electronic music keyboard also works similarly.
A speaker is a device that produces sounds from the electrical signal having audio encoded. The speakers usually have a 3.5 mm jack for audio output from the computer. Nowadays USB interface is also gaining popularity for interfacing audio devices with the computer. A lot of portable audio and musical devices nowadays have USB connector for interfacing with the computers.The USB pluggable portable devices are easy to carry away along with a laptop or notebook computer anywhere. Plus, USB is now such a universal interface that it is more common than any other computer interface for serial communication. The USB pluggable devices also have the advantage that they can draw power from the USB port itself. When USB interface is used by an audio device for connecting with the computer, the audio stream coming from the device also needs to be according to the USB protocol.
A microphone is a device that senses the sound waves and sends the digitized audio signals to the computer. The commonly used microphones have a 3.5 mm jack for audio input to the computer. Nowadays USB interface is also gaining popularity for interfacing audio devices with the computer. Even a lot of microphones and portable speakers nowadays have USB connector for interfacing with the computers.When USB interface is used by an audio device for connecting with the computer, the audio stream also needs to be sent according to the USB protocol. In this project, a typical audio jack input of a regular microphone is replaced with the USB interface to connect with a computer.