How does a computer know which device is connected to the usb port

computer-architecturehardware-detectionmotherboardusb

I was wondering that in a same USB port many devices can be connected like keyboard, mouse, storage device etc. So, how does a computer know which device is connected to the USB port, like when we plug a keyboard how does a keyboard adapater in the motherboard knows it is keyboard that is plugged in and start communicating with it?
Do each USB device send some unique information about them to the computer to be recognized by the computer?

Best Answer

Yes. USB, aka Universal Serial Bus is a connection of 4 ports. VCC, Data+, Data- and Ground, where newer specifications will have more bandwidth and power transmission.

When you connect a USB device to your computer, the computer will first supply 5v over the port and data to request an init. The other end of the USB cable, the device, will have a controller chip that handles the communication of the port. It will send a response with an identifaction code.

There is a huge list of generic identifications that it can use, or it can say other, and transmit an additional code. In case of a computer, if this happens, it will look if driveres are installed or available matching this unique identifier. If not, it will respond with: "The device was not recognized." and you can only get it to work by installing the right driver, which will add support for that unique identification code.

Once the initial stage is complete, the device goes into operation mode, and the driver will continue to communicate to the USB device.

Small sidenote: If you try to just connect leads to a USB plug, say... power +, and ground, you will find out that it does not work reliably because there is no init stage. It will go on and then off.

And please recommend me some book about these stuff.

Sorry, but asking for learning recommendations is considered Off-Topic. Its too broad and can get outdated. See the Help Center for more information.

Related Question