One reason why USB is suitable for a wide range of devices is its support for four types of data transfers.
Control transfers enable the host to learn about a device, set a device’s address, and select configurations and other settings. Control transfers can also send vendor-specific requests that transfer data for any purpose. All USB devices must support control transfers. A control transfer has two or three stages. In the Setup stage, the host sends a request. In the Data stage, the host or device sends data. Some requests don’t have a Data stage. In the Status stage, the receiver of data in the Data stage returns status information. If there is no Data stage, the device returns the status information.
The other transfer types don’t have stages. A class specification or vendor- specific protocol determines the length of a transfer. Bulk transfers are intended for situations where the rate of transfer isn’t critical. If the bus is very busy, bulk transfers are delayed, but if the bus is otherwise idle, bulk transfers are the fastest. Mass-storage devices use bulk transfers. Interrupt transfers are for devices that must receive or send data periodically. Mass-storage devices rarely use interrupt transfers except for some full-speed floppy drives, which use interrupt transfers to report the status of a received command. Isochronous transfers have guaranteed delivery time but no error correcting. Mass-storage devices don’t use isochronous transfers.
Each transfer consists of one or more transactions. Each transaction contains a token packet, a data packet, and a handshake packet. (The handshake packet isn’t present in isochronous transfers.) Each packet begins with a packet ID (PID). The function of the PID varies with the packet type.
The token packet contains the device address and the endpoint number the transaction is directed to. The token packet’s PID identifies the packet as one of these types: SETUP (first packet in a control transfer), OUT (other host-to-device packet), IN (device-to-host packet), or SOF (start-of-frame marker).
The data packet contains any data the host or device is sending in the transaction. For control transfers, the transfer stage and the request determine who sends the data. For other transfers, the endpoint’s direction determines who sends the data. The PID contains the data-toggle value, as explained below.
The handshake packet is sent by the receiver of the data packet. The PID contains a code to indicate whether the data was received without error. A code of ACK means success, NAK means busy, and STALL means either that the device doesn’t support a received request in a control transfer or that the endpoint’s Halt feature is set. High-speed bulk OUT endpoints can also return a NYET handshake code, which means that the endpoint accepted the data in the current transaction but isn’t yet ready for more data.