ELI5, how does a computer communicate with a peripheral over USB?

178 views

[ad_1]

ELI5, how does a computer communicate with a peripheral over USB?

In: Technology
[ad_2]

On a simple level, when a peripheral (an external device that performs some function) is connected to the computer, it sends information to the computer about what kind of device it is and what type of data it will be sending and receiving. USB standardizes all this information, so the computer can easily set the device up and understand the information coming from it.

The details, however, can be more complex. USB stands for Universal Serial Bus, and has been developed by [several major tech companies](https://www.usb.org/sites/default/files/usb_20g.pdf#page=1) since the 1990s. According to [GHI Electronics](https://docs.ghielectronics.com/software/netmf/tutorials/usb-host.html), USB operates by having a host (usually the computer) communicate data to and from connected devices. A USB controller in the host determines what data is used and when. The host usually takes information in through the USB-A connector, which is the standard [rectangular connector](https://www.lifewire.com/thmb/imFxGGIWfKUfN_uRvut5caFWDV4=/1500×1000/filters:fill(auto,1)/usb-extension-cable-57c768dc3df78c71b6566b04.jpg) we all recognize.

This connector has [4 pins](https://www.electroschematics.com/wp-content/uploads/2010/01/usb-wiring-connection.jpg) that send electrical signals to and from the computer. Two of these pins are used for data transfer (using [various kinds of packets](https://youtu.be/F7NlCaaL3yU?t=564)) while the other two are used for power. How each pin is used to transfer data [depends on the peripheral](https://www.cypress.com/file/134171/download#page=32).

According to [page 3 of this USB documentation](https://www.cypress.com/file/134171/download#page=3) from Cypress Semiconductor Corporation, there are 4 main ways USB transfers data. These ways are labeled as control, interrupt, bulk, and isochronous transfers.

* Control transfers configure the device and send and receive information about the device itself. This is the type of data transfer that is happening when a usb device is first plugged in, and it is what [configures the device](https://www.jungo.com/st/support/documentation/windriver/802/wdusb_man_mhtml/node55.html) for proper operation and communication with the computer.
* Interrupt transfers are the most recognizable, as they deal with how a mouse and keyboard works. Since the inputs from these are small but needed in real-time, the USB controller in the computer makes sure that they can be read quickly.
* Bulk transfers are what occurs when sending a large amount of data that is not time-sensitive, like when printing an image or transferring a file to a flash drive. In other words, it is a bunch of data that doesn’t need to get where it’s going as quickly. Because of this, the USB controller uses available USB bandwidth without any guarantee of transfer speed. This transfer type’s use of error correction makes it very reliable when dealing with a large amount of data.
* Isochronous transfers are used for live, time-sensitive media. An example of this would be a [webcam or speakers](https://youtu.be/F7NlCaaL3yU?t=495). The other transfer types check for errors along their path, but isochronous transfers continue sending information while reading an error, so that the audio or video isn’t interrupted.

USB continues to be expanded to become faster and more “universal,” but it still follows the core principles mentioned here.