Training – USB 101 – Introduction to USB
While you may see external USB ports everywhere in consumer products, USB connections do not have to be external. If your chosen MCU or CPU has USB capability, you can also consider USB for embedded connections to other MCUs or CPUs in your system. USB has built-in data encoding to help reduce electromagnetic interference and link power management for power efficiency. USB also adds flexibility for customer software where many low-level drivers already exist today.
2: How do you transmit data over a long distance when your interface’s data link reliability is lacking?
To help you understand whether the USB protocol is a good fit for your system and meets your high-speed interface needs, here are six key questions designers should consider.
Designing a system that uses high-speed signals for data transmission can be difficult, especially when there are so many available communication protocols. While many are ideal for high-speed signals, one in particular continues to grow in popularity – the USB. Often been associated with gaming, automotive head unit, and PC and notebook applications, the USB protocol has become a more general-purpose high-speed data protocol, connector and cable specification due to its support for multiple types of data transfers and high-power charging. Figure 1 shows the evolution of USB since its release in 1998.
The introduction of the USB Type-C® protocol has greatly increased USB’s flexibility. USB Type-C enables the creation of peripherals that act as a USB host or USB device, enabling systems to react to different kinds of connections in multiple ways. USB Type-C active multiplexers can also help ensure the correct configuration of the interface while providing signal integrity compliance to the USB specification.
An Introduction to the USB Protocol
The USB protocol, also known as Universal Serial Bus, was first created and introduced in 1996 as a way to institutionalize a more widespread, uniform cable and connector that could be used across a multitude of different devices. With the increase in technological devices during this time, having a universal cable would help reduce the confusion and inconvenience of having a collection of cables needed for each individual device.
The USB architecture was conceptualized with the juncture of companies including Compaq, Digital Equipment, IBM, Intel, Microsoft, and Northern Telecom, and is currently maintained and regulated by the USB Implementors Forum, or USB-IF. USB-IF enforces the standards and specifications that USB device manufactures must comply with in order to a be verified as a trusted USB source. Devices that are compliant to both the USB standard’s physical layer (mechanical and electrical) and software layer are approved to use the USB logo, informing consumers and other USB adopters that their cables or devices are safe to use.
How Does USB Transmit and Receive Data?
How does the USB standard define how a USB cable or device should operate? There are a variety of mechanisms that must be adhered to, including how various USB devices should interact with each other upon enumeration and communication.
USB hosts are also known as master devices, and they initiate all the communication that occurs over the USB bus. Typically, a computer or other controller are considered to be the master, only responding to other devices if requesting certain information. The peripheral device, or the slave device, is connected to the host device, and is programmed to provide the host device with the information it needs to operate. Typically, peripheral devices include USB flash drives, computer mice and keyboards, cameras, and other such devices.
It is important for host and peripheral devices to be able to effectively communicate with each other. If either one isn’t able to perform its job function, the communication between two devices would falter. For instance, if a user plugs in a flash device on their host computer and nothing happens, this would likely indicate a problem with the communication over the bus. Which leads into how communication takes places over the USB bus. How is USB data transmitted and received? This can be better understood by getting to know the theory of operation on how USB data is sent over the bus, the different USB data packet fields and packet types, and the types of USB data transfers.
The USB data packet fields are what make up a USB packet, consisting of individual bits.
USB data packet fields include a Sync field, a Packet ID (PID) field, ADDR (Address) field, ENDP (Endpoint) field, CRC (cyclical redundancy check) field, and EOP (end of packet) field.
Table 1: USB Packet Types
PID Type | PID Name | Description |
Token | OUT | Host to device transfer |
IN | Device to Host transfer | |
SOF | Start of Frame marker | |
SETUP | Host to device control transfer | |
Data | DATA0 | Data packet |
DATA1 | Data packet | |
DATA2 | High-Speed Data packet | |
MDATA | Split/High-Speed Data packet | |
Handshake | ACK | The data packet was received error free |
NAK | Receiver cannot accept data or the transmitter could not send data | |
STALL | Endpoint halted or control pipe request is not supported | |
NYET | No response yet | |
Special | PRE | Preamble to full-speed hub for low-speed traffic |
ERR | Error handshake for Split Transaction | |
SPLIT | Preamble to high-speed hub for low/full-speed traffic | |
PING | High-speed flow control token | |
EXT | Protocol extension token |
These fields are used to form data packets, which define the various transactions. There are four USB packet types including:
Token Packet, which is initiated by the host and determines if the host will send or receive data.
Data Packet, where the Data is sent by the transmitter, and a device can return a NAK or Stall packet to indicate if they are not able to respond.
Handshake Packet, used for acknowledging data or reporting errors.
Start-of-Frame Packet, splits the USB bus into time segments and schedules the data transfers.
These packets are formed into frames and sent through a USB transaction. The length and frequency of the transaction depends upon the transfer type being used for an endpoint.
All communication between a USB host and a USB device is addressed to a specific endpoint on the device. Each device endpoint is a unidirectional receiver or transmitter of data; either specified as a sender or receiver of data from the host.
Each endpoint is different, specified through their bandwidth requirements and the way they transfer data. The four types of USB data transfers include: Control, Isochronous, Interrupt, and Bulk transfers.
Control: Non-periodic transfers. Typically, used for device configuration, commands, and status operation.
Interrupt: This is a transaction that is guaranteed to occur within a certain time interval. The device will specify the time interval at which the host should check the device to see if there is new data. This is used by input devices such as mice and keyboards.
Isochronous: Periodic and continuous transfer for time-sensitive data. There is no error checking or retransmission of the data sent in these packets. This is used for devices that need to reserve bandwidth and have a high tolerance to errors. Examples include multimedia devices for audio and video.
Bulk: General transfer scheme for large amounts of data. This is for contexts where it is more important that the data is transmitted without errors than for the data to arrive in a timely manner. Bulk transfers have the lowest priority. If the bus is busy with other transfers, this transaction may be delayed. The data is guaranteed to arrive without error. If an error is detected in the CRCs, the data will be retransmitted. Examples of this type of transfer are files from a mass storage device or the output from a scanner.
Control System Engineer Interview Questions
The concept of serial communication is simple. The serial port sends and receives bytes of information one bit at a time. This is slower than parallel communication, which allows the transmission of an entire byte at once; however, it is simpler and can be used over longer distances.
For example, the IEEE 488 specifications for parallel communication state that the cabling between equipment can be no more than 20 meters total, with no more than 2 meters between any two devices; serial can extend as much as 1200 meters.
Typically, serial is used to transmit ASCII data. Communication is completed using 3 transmission lines:
Since serial is asynchronous, the port is able to transmit data on one line while receiving data on another. This is referred to as Full-Duplex transmission.
Other lines are available for handshaking, but are not required. The important serial characteristics are baud rate, data bits, stop bits, and parity. For two ports to communicate, these parameters must match:
Baud rate is a speed measurement for communication. It indicates the number of bit transfers per second.
For example, 300 baud is 300 bits per second. When we refer to a clock cycle, in the context of serial, we mean the baud rate.
For example, if the protocol calls for a 4800 baud rate, then the clock is running at 4800Hz.
This means that the serial port is sampling the data line at 4800Hz.
Common baud rates for telephone lines are 14400, 28800, and 33600.
Baud rates greater than these are possible, but these rates reduce the distance by which devices can be separated. These high baud rates are used for device communication where the devices are located near one another.
Data bits are a measurement of the actual data bits in a transmission.
When the computer sends a packet of information, the amount of actual data may not be a full 8 bits.
Standard values for the data packets are 5, 7, and 8 bits. Which setting you choose depends on what information you are transferring.
For example, standard ASCII has values from 0 to 127 (7 bits). Extended ASCII uses 0 to 255 (8 bits).
If the data being transferred is simple text (standard ASCII), then sending 7 bits of data per packet is sufficient for communication.
A packet refers to a single byte transfer, including start/stop bits, data bits, and parity. Since the number of actual bits depend on the protocol selected, the term packet is used to cover all instances.
Stop bits are used to signal the end of communication for a single packet.
Typical values are 1, 1.5, and 2 bits. Since the data is clocked across the lines and each device has its own clock, it is possible for the two devices to become slightly out of sync.
Therefore, the stop bits not only indicate the end of transmission but also give the computers some room for error in the clock speeds.
The more bits that are used for stop bits, the greater the lenience in synchronizing the different clocks, but the slower the data transmission rate.
Parity is a simple form of error checking that is used in serial communication.
There are four types of parity: even, odd, marked, and spaced.
The option of using no parity is also available.
For even and odd parity, the serial port will set the parity bit (the last bit after the data bits) to a value to ensure that the transmission has an even or odd number of logic high bits.
For example, if the data was 011, then for even parity, the parity bit would be 0 to keep the number of logic high bits even.
If the parity was odd, then the parity bit would be 1, resulting in 3 logic high bits.
Marked and spaced parity does not actually check the data bits, but simply sets the parity bit high for marked parity or low for spaced parity.
This allows the receiving device to know the state of a bit which enables the device to determine if noise is corrupting the data or if the transmitting and receiving devices’ clocks are out of sync.
RS-232 (ANSI/EIA-232 Standard) is the serial connection historically found on IBM-compatible PCs.
It is used for many purposes, such as connecting a mouse, printer, or modem, as well as industrial instrumentation.
Because of improvements in line drivers and cables, applications often increase the performance of RS-232 beyond the distance and speed listed in the standard.
RS-232 is limited to point-to-point connections between PC serial ports and devices. RS-232 hardware can be used for serial communication up to distances of 50 feet.
RS-422 (EIA RS-422-A Standard) is the serial connection historically used on Apple Macintosh computers.
RS-422 uses a differential electrical signal, as opposed to unbalanced signals referenced to ground with the RS-232.
Differential transmission uses two lines each for transmit and receive signals which results in greater noise immunity and longer distances as compared to the RS-232.
These advantages make RS-422 a better fit for industrial applications.
RS-485 (EIA-485 Standard) is an improvement over RS-422, because it increases the number of devices from 10 to 32 and defines the electrical characteristics necessary to ensure adequate signal voltages under maximum load.
With this enhanced multi-drop capability, you can create networks of devices connected to a single RS-485 serial port.
The noise immunity and multi-drop capability make RS-485 the serial connection of choice in industrial applications requiring many distributed devices networked to a PC or other controller for data collection, HMI, or other operations.
RS-485 is a superset of RS-422; thus, all RS-422 devices may be controlled by RS-485. RS-485 hardware may be used for serial communication with up to 4000 feet of cable.
FAQ
How does USB protocol work?
What protocol is used in USB?
Where is USB protocol used?
A maximum of 127 peripherals can be connected to a single USB host controller. USB device has a maximum speed up to 480 Mbps (for USB 2.0). Length of individual USB cable can reach up to 5 meters without a hub and 40 meters with hub. USB acts as “plug and play” device.
What are the features of the USB protocol?
A maximum of 127 peripherals can be connected to a single USB host controller. USB device has a maximum speed up to 480 Mbps (for USB 2.0). Length of individual USB cable can reach up to 5 meters without a hub and 40 meters with hub. USB acts as “plug and play” device.