Panda 2 USB Connected Detection

Hi,

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?

I like the idea suggested here http://www.tinyclr.com/forum/topic?id=3864, is this solution possible with the Panda 2 (with different registers)?

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.

Did you open vbus pin with internal pull down enabled? Not sure if the pin is directly supported but if not, use register access. I think thus will be the easiest way.

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.

The other solution that could work for me would be to write to a pendrive instead of the sd card. The pen drive could be attached to the end of the usb and the pendrive removed to offload the data.

I assume that I still need to make a modified USB cable as per TKJ Electronics » FEZ Panda and USB Host please let me know if I do not need to make these modifications.

Will the write speed and flush speed be the same to the pendrive as it would to the sdcard? Currently I can write to the SD Card in less then 1ms (required to be less then 10ms for the logger).

You will need the processor datasheet and this Home - GHI Electronics

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.

Thanks