USBGetDeviceState Macro

Microchip USB Device Library

USB Device Library Help
USBGetDeviceState Macro
C
#define USBGetDeviceState USBDeviceState
Description

This function returns the current state of the device on the USB. This function is used to determine when the device is ready to communicate on the bus. Applications should not try to send or receive data until this function returns CONFIGURED_STATE

It is also important that applications yield as much time as possible to the USBDeviceTasks() function as possible while the this function returns any value between ATTACHED_STATE through CONFIGURED_STATE

For more information about the various device states, please refer to the USB specification section 9.1 available from www.usb.org. 

Typical usage:

void main(void)
{
    USBDeviceInit()
    while(1)
    {
        USBDeviceTasks();
        if((USBGetDeviceState() < CONFIGURED_STATE) ||
           (USBIsDeviceSuspended() == TRUE))
        {
            //Either the device is not configured or we are suspended
            //  so we don't want to do execute any application code
            continue;   //go back to the top of the while loop
        }
        else
        {
            //Otherwise we are free to run user application code.
            UserApplication();
        }
    }
}
Preconditions

None

Return Values
Return Values 
Description 
The device is not attached to the bus 
The device is attached to the bus but 
The device is not officially in the powered state 
The device has received a RESET from the host 
The device has received the SET_ADDRESS command but hasn't received the STATUS stage of the command so it is still operating on address 0. 
The device has an address assigned but has not received a SET_CONFIGURATION command yet or has received a SET_CONFIGURATION with a configuration number of 0 (deconfigured) 
the device has received a non-zero SET_CONFIGURATION command is now ready for communication on the bus. 
Remarks

None

Microchip MCHPFSUSB v2.3 - Sept 20, 2008
Copyright © 2008 Microchip Technology, Inc.  All rights reserved.