USB FAQs
Contents
What is the most reliable way for a USB device to detect if the host is connected?
The only universally reliable way of detecting when the USB host is attached and powered or not is to sense the voltage level on the VBUS pin of the USB connector (ex: typically B, Mini-B or Micro-B for non-OTG USB device applications). If the VBUS pin of the USB connector has been connected to the VBUS pin of the microcontroller (and doesn’t go to any other pins, either directly or through a resistor divider), then the only way for the firmware to directly sense the voltage is to look at the values of the USB OTG VBUS comparators (namely the U1OTGSTAT<SESVD> comparator which has a suitable threshold for host VBUS boolean presence detection). These comparators are documented as being host or OTG-only features but they are enabled in the hardware and generate valid output values in USB device application as well, whenever:
- The USB module is enabled (ex: U1PWRC<USBPWR> is set).
- The USB module is not suspended.
- A sufficiently long settling time (ex: a few milliseconds) has elapsed since the last transition from a USB module disabled or suspended state to a USB module enabled and active state.
Therefore, it might be possible to implement some kind of firmware that conceptually does something like this:
USB Detached State
Periodically enable the USB module, wait the required settling time, then poll the U1OTGSTAT<SESVD> bit. If it is set (implying VBUS is present, a USB cable is attached, and the host is powered), then the firmware should transition to the USB attached state described below. If the SESVD bit is clear, the firmware should promptly disable the USB module altogether and resume using the USBID/RB5/CN27 pin normally.
USB Attached State
Keep the USB module enabled continuously and the USB stack running. Periodically check the U1OTGSTAT<SESVD> bit or enable and use the associated SESVDIF interrupt flag. If after a suitable settling time has elapsed since enabling the USB module (or transitioning from a suspended to active state) and the SESVD is detected as 0, then this means the USB cable has been unplugged (or the USB host fully powered itself down). In this case, the firmware should fully disable the USB module and transition back to the USB detached state.
What is the fastest way to upgrade a serial port application to USB?
It can be surprisingly simple if you use the Communication Device Class (CDC) firmware provided in our Microchip Libraries for Applications (MLA).
This will allow immediate connection with the emulation of a COMx port without requiring the user to write or install any driver (on Windows® 2000, XP machines, Vista, and Windows 7 machines).
Does Microchip sublicense vendor IDs and product IDs?
Yes, Microchip can sublicense its Vendor ID (VID) and assign a unique Product ID (PID) for product development purposes.
Read and fill out an online application for a Microchip VID sublicense.
What should be done with USB pins if the module is not used?
The following are the recommended connections for unused USB pins when the USB device is not connected to the host and the USB module on the device is not enabled:
Pin | Recommendation |
---|---|
VBUS | May be left unconnected/floating. |
VUSB | Even when the USB module is not enabled, connect directly to Vdd with a bypass capacitor on it (10 µF max) to limit the inrush current into the device. |
D+/D- | Configure as output pins driven to either state (high or low), or configure as an input with an external resistor (about 10 KΩ) pulling it to Vdd or Vss. If configured as an input, only the pin input leakage current will be drawn through the pins (the same current would flow if the pin was connected directly to Vdd or Vss). Both options allow the pins to be used later for either input or output without significant hardware modifications. |
USBID | Configure as an output pin driving to either state (high or low), or configure as an input with an external resistor (about 10 KΩ) pulling it to Vdd or Vss. |