English
Language : 

PIC32MX440F256H-80I Datasheet, PDF (298/646 Pages) Microchip Technology – 64/100-Pin General Purpose and USB 32-Bit Flash Microcontrollers
PIC32MX3XX/4XX
11.13 Data Transfer with a Target Device
Complete all of the following steps to discover and con-
figure a connected device.
1. Write the EP0 Control register (U1EP0) to
enable transmit and receive transfers as appro-
priate with handshaking enabled (unless iso-
chronous transfers are to be used). If the target
device is a low-speed device, also set the Low-
Speed Enable bit (U1EP0<LSPD>). If you want
the hardware to automatically retry indefinitely if
the target device asserts a NAK on the transfer,
clear the Retry Disable bit (U1EP0<RETRY-
DIS>).
Note:
Use of automatic indefinite retries can lead
to a deadlock condition if the device never
responds.
2. Set up the current buffer descriptor (EVEN or
ODD) in the appropriate direction to transfer the
desired number of bytes.
3. Set the address of the target device in the
address register (U1ADDR<6:0>).
4. Write the Token register (U1TOK) with an IN or
OUT token as appropriate for the desired end-
point. This triggers the module’s transmit state
machines to begin transmitting the token and
the data.
5. Wait for the transfer done interrupt
(U1IR<TRNIF>). This will indicate that the BD
has been released back to the microprocessor
and the transfer has completed. If the retry dis-
able bit is set, the handshake (ACK, NAK,
STALL or ERROR (0xf)) will be returned in the
BD PID field. If a stall interrupt occurs, then the
pending packet must be dequeued and the error
condition in the target device cleared. If a detach
interrupt occurs (SE0 for more than 2.5 μs), then
the target has detached (U1IR<DETACHIF>).
6. Once the transfer done interrupt
(U1IR<TRNIF>) occurs, the BD can be
examined and the next data packet queued by
returning to step 2.
Note:
USB speed, transceiver and pull-ups
should only be configured during the mod-
ule set-up phase. It is not recommended to
change these settings while the module is
enabled.
11.13.1 USB LINK STATES
Three possible link states are described in the following
subsections:
• Reset
• Idle and Suspend
• Resume Signalling
11.13.1.1 Reset
As a host, software is required to drive Reset signaling.
It may do this by setting USBRST (U1CON<4>). As per
the USB specification, the host must drive the Reset for
at least 50 ms. (This does not have to be continuous
Reset signaling. Refer to the USB 2.0 specification for
more information.) Following Reset, the host must not
initiate any downstream traffic for another 10 ms.
As a device, the USB module will assert the URSTIF
(U1IR<0>) interrupt when it has detected Reset signal-
ing for 2.5 μs. Software must perform any Reset initial-
ization processing at this time. This includes setting the
address register to 0x00 and enabling Endpoint 0. The
URSTIF interrupt will not be set again until the Reset
signaling has gone away and then has been detected
again for 2.5 μs.
11.13.1.2 Idle and Suspend
The Idle state of the USB is a constant J state. When
the USB has been Idle for 3 ms, a device should go into
suspend state. During active operation, the USB host
will send a SOF token every 1 ms, preventing a device
from going into suspend state.
Once the USB link is in the suspend state, a USB host
or device must drive resume signaling prior to initiating
any bus activity. (The USB link may also be discon-
nected.)
As a USB host, software should consider the link in
suspend state as soon as software clears the SOFEN
(U1CON<0>).
As a USB device, hardware will set the IDLEIF
(U1IR<4>) interrupt when it detects a constant Idle on
the bus for 3 ms. Software should consider the link in
suspend state when the IDLEIF interrupt is set.
Once a suspend condition has been detected, the soft-
ware may wish to place the USB hardware in a Sus-
pend mode by setting USUSPEND (U1PWRC<1>).
The hardware Suspend mode gates the USB module’s
48 MHz clock and places the USB transceiver in a Low-
Power mode.
Additionally, the user may put the PIC32MX into Sleep
mode while the link is suspended.
11.13.1.3 Driving Resume Signaling
If software wants to wake the USB from suspend state,
it may do so by setting RESUME (U1CON<2>). This
will cause the hardware to generate the proper resume
signaling (including finishing with a low-speed EOP if a
host).
A USB device should not drive resume signaling unless
the Idle state has persisted for at least 5 ms. The USB
host also must have enabled the function for remote
wake-up.
DS61143E-page 296
Preliminary
© 2008 Microchip Technology Inc.