USBpoll
Syntax
USBpoll
Overview
Poll the USB interface in order to keep it attached to the bus.
Notes
If the commands USBin or USBout are not used within a program loop, the interface will drop off the bus, therefore issue the USBpoll command to stop this happening. This command should be issued at least every 10ms if using a HID interface and at least once every 5ms for a CDC interface.
Upon exiting the USBpoll command, the state of the bus can be checked via the USB variable __USB_bDeviceState. This variable resides in a higher RAM bank of the PICmicro™ (as do all of the USB variables), which means that bank switching will take place whenever it is accessed. For this reason, the USBpoll subroutine loads this variable into a variable within Access RAM. The variable it uses is named USB_bStatus.
Several states are declared within the USB_Dev.Inc file located within the compiler’s Includes folder. These are: -
| DETACHED_STATE | 0 |
| ATTACHED_STATE | 1 |
| POWERED_STATE | 2 |
| DEFAULT_STATE | 4 |
ADDRESS_PENDING_STATE 8
| ADDRESS_STATE | 16 |
| CONFIGURED_STATE | 32 |
Within the USB_Mem.inc file, there are several bits pre-declared for each of the above states. The relevant ones are:
USB_tConnected ' Set if the USB is connected
USB_tConfigured ' Set if the USB is Configured
Example
' Wait the for USB interface to be recognised and attached
Repeat
USBpoll
Until USB_tConnected = 1 Or USB_tConfigured = 1
With newer devices, testing the USB_tConnected bit is all that is required, however, for older types such as the 18F4550, the USB_tConfigured bit has to be tested. For good measure, it may be prudent to test both of them.
See also : USBinit, USBout, USBin, Config_Start…Config_End.
