I have been trying to get a reliable USB Connected method working on the Panda 2. What I am trying to achieve is this:
When the Panda 2 starts it checks for a USB connection, if there is one then go into Mass Storage Mode so the PC can oofload data from the SD Card, if no connection then go into data logging mode.
I have not been able to get a robust way of detecting if the USB cable is plugged into a PC. For my application, the Panda is powered by it’s own dedicated 5V supply, and the USB lead is always plugged in to the panda, but not plugged into the PC. When I need to offload data I plug the lead into the PC. The Panda is remotely mounted with the USB cable and the laptop is taken to the USB lead for offload.
I tried to use USBClientController.GetState(), but that does not seem to work reliably, I suspect that because the USB cable is always plugged into the Panda it acts an an antenna and picks up noise etc. The other issue is that because windows can take a few minutes to detect the Mass Storage device I need to wait for Windows for some variable period of time, not a good solution.
Looking at the schematic, it looks like the VBUS pin from the USB device is connected to the CAN 2 TX pin, however this always reads about 2.3V even if the USB cable is not connected to the pc or even plugged into the Panda? Looking at the schematic I am not sure how this can be the case?
Ideally I would like to detect the USB cable being connected and disconnected to the PC so that I can start and stop the USB Mass Storage as required and return the Panda back to data logging when the USB is not connected.
Does anybody have any solutions or ideas? Thanks as always.
When I attach an input to the pin with the internal pull down enabled, during the bootloader process the voltage floats at abput 2.3V even with no cable plugged in, however once the application code starts running the voltage is 0V.
Which registers would I neeed to access on the Panda 2? I am concerned that even with register access the state will be incorrectly reported due to the strange VBUS voltage I am seeing.
Thanks Gus for the details. I had a look through the data sheet but I am not convinced that the register will be correct due to the circuit design.
As a workaround, I cut 2 usb cables and joined them as per TKJ Electronics » FEZ Panda and USB Host and my cheap usb memory stick (pen drive) works fine, each write is on average 0.4ms so this is the solution I will go with. It also means I can stop lugging the laptop around to offload the data.