Detect when USB is connected

26 Jul 2011

Hi All,

Is there a way to detect (in code) if the USB cable is connected on the MBD? Maybe a way to see that there is supplied power via USB plug or something like that?

Cheers!

Tim

05 Aug 2011

One way might be to connect the Vu (5.0v USB out) pin to another unused pin capable of being used for GPIO, then use a DigitalIn object to detect its state. I think you would need to place a pulldown resistor between this GPIO pin and ground as well.

Maybe there is a semihost call that can ask the interface chip if it is getting power from the USB bus?

20 Sep 2012

I tried this, however it seems that even if there is no USB cable plugged in, the pin Vu always give 5V output, so I am afraid that this is not the way to detect de cable. However, this helped me to get to the opposit process: check if there is an external energy source connected to the pin Vin using the same method, so mbed can't detect if it is connected to the computer, but it can detect whether it is connected to another source or not, and it is possible to use this for the same porpuses. However, if somebody finds out a way to detect the USB would be better of course.

Adam Green wrote:

One way might be to connect the Vu (5.0v USB out) pin to another unused pin capable of being used for GPIO, then use a DigitalIn object to detect its state. I think you would need to place a pulldown resistor between this GPIO pin and ground as well.

Maybe there is a semihost call that can ask the interface chip if it is getting power from the USB bus?