USB

Universal Serial Bus is a common serial bus standard for connectivity between devices and a host controller, usually a computer. It is frequently used with digital cameras, printers, external hard drives etc.

Hooking It Up
USB 1.x/2.0 Mini/Micro pinning Pin

USB 3 Pins

Data Packets
All USB packets are composed of 8-bits (1-byte), with the least significant bit transferred first. The first byte will be the packet identifier byte (PID), consisting of 4-bits with its bitwise complement for verification of data integrity. The PID bytes are as follows:

USB PID bytes

Packets come in 3 disserent types, with an extra potential special type.

1. Handshake Packet
Handshake packets are a PID byte, and are typically sent as ACK (data recieved), NAK (data cannot be accepted), and STALL (error has occurred). USB 2.0 has extra packets in the form of NYET (split transaction is not done/buffer is full, will PING until an ACK is received and then resumes transfer) and ERR (split transaction failed).

2. Token Packet
A Token Packet is a PID byte with 2 payload bytes, having an 11-bit address and a 5-bit CRC. The main packets are IN and OUT, consisting of a 7-bit device number and a 4-bit function number and tell a device to transmit or recieve DATAx packets respectively. IN expects a device response, being NAK or STALL, or DATAx with a possible ACK handshake. OUT follws by sending a corresponding DATAx packet, and may receive ACK, NAK, NYET, or STALL. SETUP is a special case; essentially an OUT token, but only used for device setup, and is followed by a DATA0 packet.

Each millisecond (1200 bit times at full-bandwidth), and SOF (start of frame) token is transmitted to synchronize isochronous data flow. SOF is an 11-bit address that increments each time to act as a frame of reference.

USB 2.0 has a few extra features. SOF is sent an extra 7 times per millisecond, each marked with a "microframe" bit. USE 2.0 also has a PING function to check for a ready device, and a 3-byte SPLIT function (7-bit hub number, 12 control bits, 5-bit CRC) to preform split transaction. The type of data packet used alternated between DATA0 and DATA1 to prevent duplicated. the special case SETUP required a DATA0 packet to follow. USB2.0 also adds the data packets DATA2 and MDATA for high-speed transfer.

3. Data Packet
A Data Packet is a PID followed by up to 1024 bits of data in high-bandwidth mode and 8 bytes at low bandwidthm with a 16-bit CRC. USB 1.0 contains DATA0 and DATA1 packets (address token, optional handshake, 1-bit sequence number), and waits for a handshake response.

ex. PRE Packet
Low-bandwidth devices use a special PID value called PRE. PRE is used to denote a packet that is low bandwidth. Only hubs use the PRE packet as refrence. Other devices ignore it.

Links

 * Official USB Website
 * USB Pinouts
 * USB 2.0 Specification
 * USB 3.0 Specification