237
8331B–AVR–03/12
Atmel AVR XMEGA AU
20.3
Operation
20.3.1
Start of Frame
When a start of frame (SOF) token is detected and storing of the frame numbers is enabled, the
frame number from the token is stored in the frame number register (FRAMENUM) and the start
of frame interrupt flag (SOFIF) in the interrupt flag B clear/set register (INTFLAGSBCLR/SET) is
set. If there was a CRC or bit-stuff error, the frame error (FRAMEERR) flag in FRAMENUM is
set.
20.3.2
SETUP
When a SETUP token is detected, the USB module fetches the endpoint control register (CTRL)
from the addressed output endpoint in the endpoint configuration table. If the endpoint type is
not set to control, the USB module returns to idle and waits for the next token packet.
Figure 20-3.
SETUP transaction.
The USB module then fetches the endpoint data pointer register (DATAPTR) and waits for a
DATA0 packet. If a PID error or any other PID than DATA0 is detected, the USB module returns
to idle and waits for the next token packet.
The incoming data are written to the data buffer pointed to by DATAPTR. If a bit-stuff error is
detected in the incoming data, the USB module returns to idle and waits for the next token
packet. If the number of received data bytes exceeds the endpoint's maximum data payload
size, as specified by the data size (SIZE) in the endpoint CTRL register, the remaining received
data bytes are discarded. The packet will still be checked for bit-stuff and CRC errors. Software
must never report a maximum data payload size to the host that is greater than specified in
SIZE. If there was a bit-stuff or CRC error in the packet, the USB module returns to idle and
waits for the next token packet.
If data was successfully received, an ACK handshake is returned to the host, and the number of
received data bytes, excluding the CRC, is written to the endpoint byte counter (CNT). If the
number of received data bytes is the maximum data payload specified by SIZE, no CRC data
are written in the data buffer. If the number of received data bytes is the maximum data payload
specified by SIZE minus one, only the first CRC data byte is written in the data buffer. If the num-
ber of received data bytes is equal or less than the data byte payload specified by SIZE minus
two, the two CRC data bytes are written in the data buffer.
SETUP
TOKEN
ADDRESS
ADDRESS
MATCH?
ENDPOINT
LEGAL
ENDPOINT?
EP TYPE
CTRL SET?
PID
PID OK?
DATA
BIT STUFF
BIT STUFF
OK?
CRC OK?
ACK
IDLE
o
N
o
N
o
N
o
N
o
N
o
N
READ
CONFIG
UPDATE
STATUS
STORE
DATA
s
e
Y
s
e
Y
Yes
Yes
Yes
Yes
CRC