USB Host sp'rments

Ok - in working further on the camera issue, I wrote a new app to see if I could get the USB Host to work.
I implemented using USBHostController rather than the Gadgeteer modules.
Hardware is set up with USBClientDP + external power on 1, USB Host module on 3 - nothing else attached.

When I insert a USB device (I’ve tried 3 so far - 2 thumb drive, 1 gps), I invariably get a BadConnectionEvent. The device struct that is passed in is essentially empty (all values 0, except INTERFACE_INDEX is 255 (-1).

So - The host code recognizes that something was plugged in, but apparently can’t communicate enough to get any further.

Any suggestions on digging deeper on this?

The program debug output is:
starting
last error: 0
No devices
bad connect event:
USB Device: (Type: 0:0:0:255:0:0)

And - I figured out how to flash the main board green LED :^)


namespace EMX_Application1
{
    using System.Threading;
    using GHIElectronics.NETMF.Hardware;
    using GHIElectronics.NETMF.USBHost;
    using Microsoft.SPOT;
    using Microsoft.SPOT.Hardware;

    public class Program
    {
        static bool connected = false;

        public static void Main()
        {
            Debug.Print("starting");

            USBHostController.DeviceDisconnectedEvent += new USBH_DeviceConnectionEventHandler(USBHostController_DeviceDisconnectedEvent);
            USBHostController.DeviceDisconnectedEvent += new USBH_DeviceConnectionEventHandler(USBHostController_DeviceDisconnectedEvent);
            USBHostController.DeviceBadConnectionEvent += new USBH_DeviceConnectionEventHandler(USBHostController_DeviceBadConnectionEvent);

            System.Threading.Thread ledThread = new Thread(AnotherThread);
            ledThread.Start();

            int cnt = 0;
            while (true)
            {
                if (connected)
                {
                    Debug.Print("connected " + cnt.ToString());
                    ++cnt;
                }
                else
                {
                    USBH_ERROR err = USBHostController.GetLastError();
                    Debug.Print("last error: " + err.ToString());
                }

                int idx = 0;
                foreach (USBH_Device device in USBHostController.GetDevices())
                {
                    Debug.Print("device " + idx.ToString());
                    PrintDevice(device);
                    ++idx;
                }

                if (idx == 0)
                {
                    Debug.Print("No devices");
                }

                Thread.Sleep(60000);
            }
        }

        static void  USBHostController_DeviceBadConnectionEvent(GHIElectronics.NETMF.USBHost.USBH_Device device)
        {
            Debug.Print("bad connect event:");
            PrintDevice(device);
        }

        static void USBHostController_DeviceDisconnectedEvent(GHIElectronics.NETMF.USBHost.USBH_Device device)
        {
            Debug.Print("disconnect " + device.ID.ToString());
        }

        static void USBHostController_DeviceConnectedEvent(GHIElectronics.NETMF.USBHost.USBH_Device device)
        {
            PrintDevice(device);
        }

        static void PrintDevice(USBH_Device device)
        {
            Debug.Print("USB Device: (Type: "
                + device.TYPE.ToString()
                + ":" + device.VENDOR_ID.ToString()
                + ":" + device.PRODUCT_ID.ToString()
                + ":" + device.INTERFACE_INDEX.ToString()
                + ":" + device.PORT_NUMBER.ToString()
                + ":" + device.ID.ToString()
                + ")");
        }

        static void AnotherThread()
        {
            OutputPort op1 = new OutputPort(EMX.Pin.IO47, false);
            bool state = false;

            while (true)
            {
                op1.Write(state);
                if (state)
                {
                    Thread.Sleep(250);
                }
                else
                {
                    Thread.Sleep(750);
                }

                state = !state;
            }
        }
    }
}

You probably need to connect external power to USB DP module. Or connect the USB DP module through a powered hub.

He is already using external power joe! I really want to get a hold of this board to see how it is detecting a device but able to run it!!