The full name of USB is Universal Serial Bus (English: Universal Serial Bus). The USB protocol or Universal Serial Bus was originally developed and launched by Ajay Bhatt of Intel in 1996. Universal Serial Bus (USB) is a widely adopted interface standard for connecting devices to computers, enabling data transfer, power transfer, and communication between devices.
The USB protocol is a set of rules and standards for managing device communication over USB connections. It is essential knowledge for individuals who use USB devices or develop USB-based applications. The USB protocol defines the structure of data packets, the timing of data transfer, and the electrical characteristics of the connection.
The Universal Serial Bus is designed to implement hot plugging and enhanced plug and play. Plug and play allows the operating system to spontaneously configure and discover new peripherals without starting the computer, while hot plugging allows new peripherals to be removed and replaced without restarting. There are different types of USB connectors on the market, of which Type A and Type B are the most commonly used. Currently, the older connectors have been replaced by Mini-USB, Micro-USB, and USB-C cables, and the typical Type A USB connector is used in various applications. These USBs include the 4 pins given below. This type of USB is mainly used to connect various devices to the PC as it is a typical four-pin USB connector. This connector is taller and narrower and includes 4 pins arranged inside a box.

The pins of the Type A USB are represented by colored lines to perform specific functions, PIN1 (VBUS): Red line for power supply, PIN2 (D-): White differential pair pin for USB connection, PIN3 (D+): Green differential pair pin for USB connection, Pin4 (GND): Black ground pin, In the above pins, both D+ and D- pins represent data transmission. When a "1" is sent through the line, the D+ line will have a forward flow, and if a "0" is sent, a reverse flow occurs.

In this architecture, I/O devices are connected to the computer through USB, which is called a hub. The hub in the architecture is the connection point between the I/O device and the computer. The root hub in this architecture is used to connect the entire structure to the host computer. The I/O devices in this architecture include keyboards, mice, speakers, cameras, etc.
How does USB protocol work? The USB protocol works only on the polling principle, because in polling, the processor keeps checking whether the input/output device is ready to transfer data. Therefore, the I/O device does not have to update its status to the processor, because the main responsibility of the processor is to keep checking. Therefore, this will make USB low-cost and simple. Whenever a new device is connected to the hub, its address is "0". In normal circumstances, the host will poll the hub to get its status, so that the host knows whether the I/O devices in the system are connected or disconnected from the system. Once the host responds to the new device, it will know the device capabilities by reading the available data in the specific memory of the device's USB interface. This way the host uses the appropriate driver to communicate with the device. After that, the host assigns an address to the new device, which is written to the device registers. With this device, USB provides plug-and-play capabilities. Another feature of the USB protocol is "hot plugging", which means that I/O devices can be connected or removed from the host system without shutting down or restarting. Therefore, the system will continue to operate regardless of whether I/O devices are connected or disconnected. The USB protocol can also support isochronous communication, as long as data is transferred at preset time intervals. Isochronous data transfer is very fast compared to synchronous and asynchronous data transfer. To maintain the isochronous nature of the communication, the root hub transmits a series of bits over the USB that specify the start of the isochronous data, and the actual data can be transferred after this series of bits.
The USB protocol timing diagram is shown below and is mainly used in the engineering field to explain the on/off values ​​of the USB line along the time axis, with "1" representing no charge and "0" representing activity. You can observe the on/off progression over time. The system below shows non-return-to-zero inverted (NRZI) encoding, which is a more efficient method of data transfer.

USB information format, USB protocol data is transmitted in LSB first in the data packet, and there are four main types of SB data packets: token, data, handshake, and frame start. Each data packet is designed with various field types, as shown in the information format diagram below.

SYNC: In the USB protocol, each USB data packet starts with a SYNC field, which is usually used to synchronize the sender and receiver for accurate data transmission. In low-speed or full-speed USB systems, the SYNC field contains 3 pairs of KJ sequences, followed by 2 Ks, which are used to form 8 bits of data. In high-speed USB systems, synchronization requires 15 pairs of KJ sequences, followed by 2 Ks, which are used to form 32 bits of data. The length of this field is 8 bits in low-speed and full-speed modes, and 32 bits in high-speed mode. Its purpose is to synchronize the clock (CLK) of the sender and receiver. The last 2 bits indicate the starting position of the PID field
PID: The packet identifier field in the USB protocol is mainly used to identify the type of data packet being transmitted, thereby identifying the data packet format. This field is 8 bits long, of which the upper 4 bits identify the data packet type, and the lower 4 bits are the bit-by-bit complement of the upper 4 bits
Address: The address field of the USB protocol indicates which device the data packet is mainly intended for. The 7-bit length only allows support for 127 devices. Address zero is invalid because any device that has not yet been assigned an address should respond to a data packet transmitted to the zero address.
Endpoint: The endpoint field in the USB protocol is 4 bits long, allowing additional flexibility in addressing. Typically, these fields are divided into data input/output. Endpoint "0" is a special case called a control endpoint, and each device contains an endpoint 0.
Data: The length of the data field is not fixed, so its length ranges from 0 to 8192 bits and is always an integer number of bytes, followed by a cyclic redundancy check (CRC), which is performed on the data in the packet payload, where all token packets contain a 5-bit CRC and data packets contain a 16-bit CRC. CRC-5 is 5 bits long and is used by token packets as well as the beginning of frame packets. Each packet ends with an EOP (End of the Packet) field, which includes SE0 (single-ended zero) for 2 bit times, followed by J for 1 bit time.