This is a great one... 1) Set the USB stack to interrupt mode (#define USB_INTERRUPT, #undef USB_POLLED). Set up for a self-powered (device has own PSU, does not use Vbus) device with Vbus sensing. 2) Program your target board. 3) Unplug the PSU and USB. 4) Plug in the power 5) Now plug in the USB cable. Did the device enumerate? I'll bet it didn't! Here's why. #if defined(__18CXX) void main(void) #else int main(void) #endif { InitializeSystem(); #if defined(USB_INTERRUPT) USBDeviceAttach(); #endif while(1) { ProcessIO(); } } And what does USBDeviceAttach do? #if defined(USB_INTERRUPT) void USBDeviceAttach(void) { //if we are in the detached state if(USBDeviceState =3D=3D DETACHED_STATE) { if(USB_BUS_SENSE =3D=3D 1) { //Initialize registers to known states. U1CON =3D 0; // Mask all USB interrupts U1IE =3D 0; //Configure things like: pull ups, full/low-speed mode, //set the ping pong mode, and set internal transceiver SetConfigurationOptions(); USBEnableInterrupts(); // Enable module & attach to bus while(!U1CONbits.USBEN){U1CONbits.USBEN =3D 1;} //moved to the attached state USBDeviceState =3D ATTACHED_STATE; #ifdef USB_SUPPORT_OTG U1OTGCON =3D USB_OTG_DPLUS_ENABLE | USB_OTG_ENABLE; #endif } } } Oh dear... it's responsible for enabling the USB interrupts and booting=20 up the PHY! So what happens when the USB cable isn't plugged in when the PIC=20 cold-boots? Take a guess. If you said "It gets stuck in the while loop in main, without ever=20 setting up the USB stack", you're absolutely, one hundred percent right. And how do we fix this colossal, monumental, astronomical cock-up? Rewrite main(). #if defined(__18CXX) void main(void) #else int main(void) #endif { InitializeSystem(); while(1) { #if defined(USB_INTERRUPT) if (USB_BUS_SENSE) { USBDeviceAttach(); } else { USBDeviceDetach(); } #endif ProcessIO(); } } Now the code checks the state of the Bus Sense line every time it goes=20 through the while loop, and tells the stack what's going on every step=20 of the way. It costs us about a dozen clock cycles per spin, but it=20 solves the bug quite nicely. Confirmed on v2.7a, still present in the USB Generic LibUSB demo for=20 v2.8. Oh dear... The score now stands at: Bugs I've found in Microchip appnotes or sample code -- 3 Bugs I've fixed in Microchip appnotes or sample code -- 2 Happy days. TTFN, --=20 Phil. piclist@philpem.me.uk http://www.philpem.me.uk/ --=20 http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .