2

Using the Keil USB HID example I was finally able to get my device which uses a LPC2148 to enumerate in Windows successfully; the USB HID example required some tweaking. I am using interrupt method of transfer. I am using USBlyzer to sniff my USB data transfers.

On the Windows side I am currently using a C# USB library (http://www.codeproject.com/Articles/18099/A-USB-HID-Component-for-C) to connect to my device.

My goal to test the data transfer is to send a byte to the device have it perform some trivial math operation (such as adding 2) and sending back the new value so I can verify the math was done correctly and the data was sent and received properly.

Right now it is enumerated but I am having troubles getting the LPC2148 to send/receive data. I found this article (http://www.keil.com/forum/19713/) which explained how to send data to the host.

It had the following code:

usbuser.c

#if USB_CONFIGURE_EVENT
void USB_Configure_Event (void) {
    if (USB_Configuration) {                  /* Check if USB is configured */
        GetInReport();
        USB_WriteEP(0x81, &InReport, sizeof(InReport));
    }
}
#endif

void USB_EndPoint1 (DWORD event) {

    switch (event) {
        case USB_EVT_IN:
        GetInReport();
        USB_WriteEP(0x81, &InReport, sizeof(InReport));
    break;
    }
}

I used this technique but found several problems: 1. It send continuously and very fast whereas I only want it to send data after it receives a byte of data and I only want it to send once. 2. It would appear as though GetInReport was doing nothing because in my method with this name I had it update InReport with a variable which was constantly being incremented by 1. But in my received data it always stayed the default value and never changed. 3. This code has no place for me to receive data from the computer.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Wesley Carlsen
  • 137
  • 3
  • 19

1 Answers1

1

Try to change your receive endpoint from interrupt to bulk mode in "usbdesc.c" as follows:

/* Endpoint, HID Interrupt In */
 USB_ENDPOINT_DESC_SIZE,            /* bLength */
 USB_ENDPOINT_DESCRIPTOR_TYPE,      /* bDescriptorType */
 USB_ENDPOINT_IN(1),                /* bEndpointAddress */
 //USB_ENDPOINT_TYPE_INTERRUPT,       /* bmAttributes */
 USB_ENDPOINT_TYPE_BULK,  //--Here
 WBVAL(0x0004),                     /* wMaxPacketSize */
 ...........
  • I was under the impression for my needs Interrupt is the best transfer method. I believe I have found another couple links on how to add endpoint out declerations. My biggest problem now is my USB only connects sometimes and doesn't behave right when it does. – Wesley Carlsen Aug 12 '13 at 16:04