Microchip Technology DM240015 Data Sheet

Page of 472
 2012-2013 Microchip Technology Inc.
 
DS30009312B-page 277
PIC24FJ128GC010 FAMILY
19.5.2
COMPLETE A CONTROL 
TRANSACTION TO A CONNECTED 
DEVICE 
1.
Follow the procedure described in 
 to discover a device.
2.
Set up the Endpoint Control register for
bidirectional control transfers by writing 0Dh to
U1EP0 (this sets the EPCONDIS, EPTXEN and
EPHSHK bits).
3.
Place a copy of the device framework setup
command in a memory buffer. See Chapter 9 of
the “USB 2.0 Specification” for information on
the device framework command set.
4.
Initialize the Buffer Descriptor (BD) for the
current (even or odd) TX EP0 to transfer the
eight bytes of command data for a device
framework command (i.e., GET DEVICE
DESCRIPTOR
):
a)
Set the BD Data Buffer Address (BD0ADR)
to the starting address of the 8-byte
memory buffer containing the command.
b)
Write 8008h to BD0STAT (this sets the
UOWN bit and sets a byte count of 8).
5.
Set the USB device 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 will be set to another
value between 1 and 127.
6.
Write D0h to U1TOK; this is a SETUP token to
Endpoint 0, the target device’s default control
pipe. This initiates a SETUP token on the bus,
followed by a data packet. The device hand-
shake is returned in the PID field of BD0STAT
after the packets are complete. When the USB
module updates BD0STAT, a Token Complete
Interrupt Flag is asserted (the TRNIF flag is set).
This completes the setup phase of the setup
transaction, as referenced in Chapter 9 of the
“USB 2.0 Specification”
.
7.
To initiate the data phase of the setup transac-
tion (i.e., get the data for the GET DEVICE
DESCRIPTOR
 command), set up a buffer in
memory to store the received data.
8.
Initialize the current (even or odd) RX or TX (RX
for IN, TX for OUT) EP0 BD to transfer the data. 
a) Write C040h to BD0STAT. This sets the
UOWN, configures Data Toggle (DTS) to
DATA1 and sets the byte count to the length
of the data buffer (64 or 40h in this case).
b) Set BD0ADR to the starting address of the
data buffer.
9.
Write the Token register with the appropriate IN
or OUT token to Endpoint 0, the target device’s
default control pipe (e.g., write 90h to U1TOK for
an IN token for a GET DEVICE DESCRIPTOR
command). This initiates an IN token on the bus,
followed by a data packet from the device to the
host. When the data packet completes, the
BD0STAT is written and a Token Complete Inter-
rupt Flag is asserted (the TRNIF flag is set). For
control transfers with a single packet data
phase, this completes the data phase of the
setup transaction, as referenced in Chapter 9 of
the “USB 2.0 Specification”. If more data needs
to be transferred, return to Step 8.
10. To initiate the status phase of the setup transac-
tion, set up a buffer in memory to receive or send
the zero length status phase data packet.
11. Initialize the current (even or odd) TX EP0 BD to
transfer the status data:
a) Set the BDT buffer address field to the start
address of the data buffer.
b) Write 8000h to BD0STAT (set UOWN bit,
configure DTS to DATA0 and set byte count
to 0).
12. Write the Token register with the appropriate IN
or OUT token to Endpoint 0, the target device’s
default control pipe (e.g., write 01h to U1TOK for
an OUT token for a GET DEVICE DESCRIPTOR
command). This initiates an OUT 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 Token Complete
Interrupt Flag is asserted (the TRNIF flag is set).
This completes the status phase of the setup
transaction, as described in Chapter 9 of the
“USB 2.0 Specification”
Note:
Only one control transaction can be
performed per frame.