How do I detect if a USB host is connected to my device?
In a self-powered system, it is generally desirable to be able to detect the presence of VBUS. VBUS indicates when a host device has been connected to or disconnected from the USB peripheral.
For EFM8 devices, the VBUS signal may be enabled on a port pin and configured to generate system interrupts if the state changes. The VBUS control bits are found in the USB0CF register. VBUSEN enables the VBUS pin as an input to the USB module, while the VBUSIE bit enables the associated interrupt. VBUSI will be set any time the state of VBUS changes, and firmware may then read the state of the VBUS pin and act accordingly.
For C8051 devices such as the C8051F320 and C8051F340, the VBSTAT bit in register REG0CN indicates the current logic level of the VBUS signal. It is possible to enable a VBUS interrupt that triggers when VBUS is connected.