Выбрать главу

The USB bus specification comes in two versions: the earlier version, USB1.1, supports 11Mbps, while the new version, USB 2.0, supports up to 480Mbps. The USB specification defines three data speeds:

• Low speed — 1.5Mb/sec

• Full speed — 12Mb/sec

• High speed — 480Mb/sec

The maximum power available to an external device is limited to about 100mA at 5.0V.

USB is a four-wire interface implemented using a four-core shielded cable. Two types of connectors are specified and used: Type A and Type B. Figure 8.1 shows typical USB connectors. Figure 8.2 shows the pin-out of the USB connectors.

Figure 8.1: USB connectors

Figure 8.2: Pin-out of USB connectors

The signal wire colors are specified. The pins and wire colors of a Type A or Type B connector are given in Table 8.1.

Table 8.1: USB connector pin assignments

Pin no. Name Color
1 +5.0V Red
2 Data– White
3 Data+ Green
4 Ground Black

The specification also defines a mini-B connector, mainly used in smaller portable electronic devices such as cameras and other handheld devices. This connector has a fifth pin called ID, though this pin is not used. The pin assignment and wire colors of a mini-B connector are given in Table 8.2.

Table 8.2: Mini USB pin assignments

Pin no. Name Color
1 +5.0V Red
2 –Data White
3 +Data Green
4 Not used
5 Ground Black

Two of the pins, Data+ and Data–, form a twisted pair and carry differential data signals and some single-ended data states.

USB signals are bi-phase, and signals are sent from the host computer using the NRZI (non-return to zero inverted) data encoding technique. In this technique, the signal level is inverted for each change to a logic 0. The signal level for a logic 1 is not changed. A 0 bit is “stuffed” after every six consecutive ones in the data stream to make the data dynamic (this is called bit stuffing because the extra bit lengthens the data stream). Figure 8.3 shows how the NRZI is implemented.

Figure 8.3: NRZI data

A packet of data transmitted by the host is sent to every device connected to the bus, traveling downward through the chain of hubs. All the devices receive the signal, but only one of them, the addressed one, accepts the data. Conversely, only one device at any time can transmit to the host, and the data travels upward through the chain of hubs until it reaches the host.

USB devices attached to the bus may be full-custom devices, requiring a full-custom device driver, or they may belong to a device class. Device classes enable the same device driver to be used for several devices having similar functionalities. For example, a printer device has the device class 0x07, and most printers use drivers of this type.

The most common device classes are given in Table 8.3. The USB human interface device (HID) class is of particular interest, as it is used in the projects in this chapter.

Table 8.3: USB device classes

Device class Description Example device
0x00 Reserved
0x01 USB audio device Sound card
0x02 USB communications device Modem, fax
0x03 USB human interface device Keyboard, mouse
0x07 USB printer device Printer
0x08 USB mass storage device Memory card, flash drive
0x09 USB hub device Hubs
0x0B USB smart card reader device Card reader
0x0E USB video device Webcam, scanner
0xE0 USB wireless device Bluetooth

Some common USB terms are:

Endpoint: An endpoint is either a source or a sink of data. A single USB device can have a number of endpoints, the limit being sixteen IN and sixteen OUT endpoints.

Transaction: A transaction is a transfer of data on the bus.

Pipe: A pipe is a logical data connection between the host and an endpoint.

8.1 Speed Identification on the Bus

At the device end of the bus, a 1.5K pull-up resistor is connected from the D+ or D– line to 3.3V. On a full-speed bus, the resistor is connected from the D+ line to 3.3V, and on a low-speed bus the resistor is from D– line to 3.3V. When no device is plugged in, the host will see both data lines as low. Connecting a device to the bus will pull either the D+ or the D– line to logic high, and the host will know that a device is plugged into the bus. The speed of the device is determined by observing which line is pulled high.