How do I detect when a self powered device is plugged in?

Question: How do I detect when a self powered device is plugged in?

 

Answer:

The best way to detect when the USB cable is plugged in is to monitor VBUS with one of the I/O port pins. VBUS can be either monitored in the main loop or another popular method is to set up an interrupt timer to a fixed interval and in the interrupt ISR
look at the port pin (VBUS). You can then take the appropriate action depending on state of VBUS.  Please go through application note "Monitoring the VBUS for EZ-USB FX2LP" for more details on implementing VBUS monitoring.