11 years, 5 months ago.

USB device code examples hanging when not plugged into PC

Trying out the different USB code examples if I run the mbed whilst the USB is not connect the different examples hang. My application is a data logger where I wish to store data then after a period of time connect the logger via USB to download the data, how would I modify the examples so that the code will run when not connected to the PC and will detect the PC connection when needed?

At the moment, in the USBDevice library, there is nothing to detect if there is a connection to the PC or not. What you can do is remove the connect() function (which is a blocking) from the constructor of your USBDevice and call it whenever you want later in your code. For instance, if you are using USBHID, you can comment in USBHID.cpp the connect() call. When you have finished to log your data, you call hid.connect() to connect the usb device.

posted by Samuel Mokrani 07 Nov 2012

2 Answers

11 years, 5 months ago.

I am sure you can look for power on PC-USB lines,

at worst, connect a 10K resistor from PC-USB 5Volts, to an I/P pin.

but I think that you can do something with D+,D-

Ceri

Accepted Answer
10 years, 6 months ago.

I am looking into this issue also - related at least. Hoping to get some response from someone in the mbed project soon:

https://github.com/mbedmicro/mbed/issues/53