Книга: Advanced PIC Microcontroller Projects in C

8.3.1 Packets

8.3.1 Packets

Data is transmitted on a USB bus in packets. A packet starts with a sync pattern to allow the receiver clock to synchronize with the data. The data bytes of the packet follow, ending with an end of packet signal.

A packet identifier (PID) byte immediately follows the sync field of every USB packet. A PID itself is 4 bits long, and the 4 bits are repeated in a complemented form. There are seventeen different PID values, as shown in Table 8.4. These include one reserved value and one that is used twice, with two different meanings.

Table 8.4: PID values

PID type PID name Bits Description
Token OUT 1110 0001 Host to device transaction
IN 0110 1001 Device to host transaction
SOF 1010 0101 Start of frame
SETUP 0010 1101 Setup command
Data DATA0 1100 0011 Data packet PID even
DATA1 0100 1011 Data packet PID odd
DATA2 1000 0111 Data packet PID high speed
MDATA 0000 1111 Data packet PID high speed
Handshake ACK 1101 0010 Receiver accepts packet
NAK 0101 1010 Receiver does not accept packet
STALL 0001 1110 Stalled
NYET 1001 0110 No response from receiver
Special PRE 0011 1100 Host preamble
ERR 0011 1100 Split transaction error
SPLIT 0111 1000 High-speed split transaction
PING 1011 0100 High-speed flow control
Reserved 1111 0000 Reserved

There are four packet formats, based on which PID is at the start of the packet: token packets, data packets, handshake packets, and special packets.

Figure 8.4 shows the format of a token packet, which is used for OUT, IN, SOF (start of frame), and SETUP. The packet contains a 7-bit address, a 4-bit ENDP (endpoint number), a 5-bit CRC checksum, and an EOP (end of packet).


Figure 8.4: Token packet

A data packet is used for DATA0, DATA1, DATA2, and MDATA data transactions. The packet format is shown in Figure 8.5 and consists of the PID, 0–1024 bytes of data, a 2-byte CRC checksum, and an EOP.


Figure 8.5: Data packet

Figure 8.6 shows the format of a handshake packet, which is used for ACK, NAK, STALL, and NYET. ACK is used when a receiver acknowledges that it has received an error-free data packet. NAK is used when the receiving device cannot accept the packet. STALL indicates when the endpoint is halted, and NYET is used when there is no response from the receiver.


Figure 8.6: Handshake packet

Оглавление книги

Оглавление статьи/книги

Генерация: 0.558. Запросов К БД/Cache: 2 / 0
поделиться
Вверх Вниз