title: LPC2148 USB Send/Receive Data
body: <p>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.</p>
  
  <p>On the Windows side I am currently using a C# USB library (<a href="http://www.codeproject.com/Articles/18099/A-USB-HID-Component-for-C" rel="nofollow">http://www.codeproject.com/Articles/18099/A-USB-HID-Component-for-C</a>) to connect to my device.</p>
  
  <p>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.</p>
  
  <p>Right now it is enumerated but I am having troubles getting the LPC2148 to send/receive data. I found this article (<a href="http://www.keil.com/forum/19713/" rel="nofollow">http://www.keil.com/forum/19713/</a>) which explained how to send data to the host.</p>
  
  <p>It had the following code:</p>
  
  <p>usbuser.c</p>
  
  <pre><code>#if USB_CONFIGURE_EVENT
  void USB_Configure_Event (void) {
      if (USB_Configuration) {                  /* Check if USB is configured */
          GetInReport();
          USB_WriteEP(0x81, &amp;InReport, sizeof(InReport));
      }
  }
  #endif
  
  void USB_EndPoint1 (DWORD event) {
  
      switch (event) {
          case USB_EVT_IN:
          GetInReport();
          USB_WriteEP(0x81, &amp;InReport, sizeof(InReport));
      break;
      }
  }
  </code></pre>
  
  <p>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.</p>