Hi Steve,
Dedicate a single I/O-pin as USB bus sense. Use a large value pull-down resistor of around 100K to pull this pin to ground when the USB cable is not connected.
Connect the node between this pin and the pull-down to USB +V on your USB cable connector. Once the USB cable is plugged in, the USB sense pin will be pulled-up to +V.
Until this pin senses the USB connection, have your program avoid calling any USB sub-routines or issuing any USB commands. This is how Microchip does it with the USB PIC demo board.
You might want to download the docs for the Microchip USB demo board and take a peek at the schematics/code for reference.
Bookmarks