English
Language : 

PIC32MX440F256H-80I Datasheet, PDF (297/646 Pages) Microchip Technology – 64/100-Pin General Purpose and USB 32-Bit Flash Microcontrollers
11.12 Completing a Control Transaction
to a Connected Device
Complete all of the following steps to discover a con-
nected device:
1. Set up the Endpoint Control register for bidirec-
tional control transfers, U1EP0<4:0> = 0x0D.
2. Place an 8-byte of the device setup packet in the
appropriate memory buffer. See Chapter 9 of
the USB 2.0 specification for information on the
device framework command set.
3. Initialize the current (EVEN or ODD) TX EP0 BD
to transfer the 8 byte device framework com-
mand (for example, a GET DEVICE DESCRIP-
TOR command).
a) Set the BD status (BD0STAT) to 0x8008 –
UOWN bit set, byte count of 8.
b) Set the BD data buffer address (BD0ADR)
to the starting address of the 8-byte
memory buffer containing the command, if it
is not already initialized.
4. Set the USB address of the target device in the
address register U1ADDR<6:0>. After a USB
bus Reset, the device USB address will be zero.
After enumeration, it must be set to another
value, between 1 and 127, by the host software.
5. Write the token register with a SETUP command
to Endpoint 0, the target device’s default control
pipe (U1TOK = 0xD0). This will initiate a SETUP
token on the bus followed by a data packet. The
device handshake will be returned in the PID
field of BD0STAT after the packets complete.
When the module updates BD0STAT, a transfer
done interrupt will be asserted (U1IR<TRNIF>).
This completes the setup stage of the setup
transfer as described in Chapter 9 of the USB
specification.
6. To initiate the data stage of the setup transaction
(for example, get the data for the GET DEVICE
DESCRIPTOR command), set up a buffer in
memory to store the received data.
7. Initialize the current (EVEN or ODD) RX or TX
(RX for IN, TX for OUT) EP0 BD to transfer the
data.
a) Set the BD status (BD0STAT) UOWN bit to
‘1’, data toggle (DTS) to DATA1 and byte
count to the length of the data buffer.
b) Set the BD data buffer address (BD0ADR)
to the starting address of the data buffer if it
is not already initialized.
PIC32MX3XX/4XX
8. Write the Token register with the appropriate IN
or OUT token to Endpoint 0, the target device’s
default control pipe) for example, an IN token for
a GET DEVICE DESCRIPTOR command
(U1TOK = 0x90). This will initiate an IN token on
the bus followed by a data packet from the
device to the host. When the data packet com-
pletes, the BD0STAT is written and a transfer
done interrupt will be asserted (U1IR<TRNIF>).
For control transfers with a single packet data
phase, this completes the data phase of the
setup transaction. If more data needs to be
transferred, return to step 8.
9. To initiate the status stage of the setup transac-
tion, set up a buffer in memory to receive or send
the zero length status phase data packet.
10. Initialize the current (EVEN or ODD) TX EP0 BD
to transfer the status data.
a) Set the BD status (BD0STAT) to 0x8000 –
UOWN bit to ‘1’, data toggle (DTS) to
DATA0 and byte count to ‘0’.
b) Set the BDT buffer address field to the start
address of the data buffer.
11. Write the Token register with the appropriate IN
or OUT token to Endpoint 0, the target device’s
default control pipe) for example, an OUT token
for a GET DEVICE DESCRIPTOR command
(U1TOK = 0x10). This will initiate a token on the
bus, followed by a zero length data packet from
the host to the device. When the data packet
completes, the BD is updated with the hand-
shake from the device, and a transfer done inter-
rupt will be asserted (U1IR<TRNIF>). This
completes the status phase of the setup
transaction.
Note: Some devices can only effectively
respond to one transaction per frame.
© 2008 Microchip Technology Inc.
Preliminary
DS61143E-page 295