How USB Works

Last modified by Microchip on 2023/11/10 11:19

How USB Communicates

All USB data transfers are initiated by the USB host. The host controls communication timing by maintaining time intervals called frames. The host issues a Start of Frame (SOF) sequence on the USB data lines at the beginning of each frame.

The time interval of each frame is determined by the specified USB speed. One requirement of USB compliance certification is the ability of a host to accurately issue SOFs.

The USB host conducts communication transactions with the devices during the frame.

USB frame diagram

Back to top

How USB Transfers Data

The mechanism of transferring data involves the host reading and writing to a set of memory locations on each device. These memory locations are called endpoints. Endpoints are essentially in-and-out baskets. The size of an endpoint (i.e., the amount of data in an endpoint) can vary significantly between different devices.

Device endpoints are found in numbered pairs. Endpoint numbers start at 0 and can be as high as 32. Each endpoint number has an IN and an OUT endpoint. OUT endpoints carry data coming out of the host, while IN endpoints contain data being sent into the host. For example, Endpoint 1 is two endpoints; endpoint 1 IN ( EP1IN) and Endpoint 1 OUT ( EP1OUT).

Back to top

Writing to a USB Device

When the host wishes to send a message to a device, the message is placed in an OUT endpoint on the device through the use of a WRITE transaction. The device’s application code monitors the OUT endpoints to determine if any messages have been received from the host. After detecting the presence of a message from the host, the device will copy the message from the OUT endpoint.

Writing to a USB device process

Back to top

Sending Data to the Host

If a device’s application wishes to communicate with the host, a message is placed in an IN endpoint. The message will remain in the IN endpoint until the host issues a READ transaction. A READ transaction caused the contents of an IN endpoint to be sent to the host.

Sending data to USB host process

Back to top

Communication Parameters

The data throughput of USB communications to an endpoint depends upon three items:

  1. The specified USB speed determines the signaling rate of the frame.
  2. The size of the endpoint (how much data each transaction moves).
  3. The frequency with which the host issues transactions to the endpoint. This can vary from several transactions per frame to multiple frames between endpoint transactions.

Information on all endpoint parameters and communication requirements is defined by the device and given to the host when the device is plugged into the host and successfully enumerated. The enumeration process informs the host which transfer type to use when communicating with a device’s endpoints.

Back to top

Control and Communications

Each USB device reserves Endpoint 0 as a unique endpoint called the control endpoint. EP0 IN contains a description of the USB device, which is read by the host during enumeration. EP0 OUT provides the host the ability to send configuration commands to the device.  In addition to the control commands sent to devices during operation, three unique signaling conditions can be issued by the host: Reset, Suspend, or Restore a suspended device.

Back to top

Learn More

Back to top