This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

LPC1343 USB HID Example automatically sends data to PC?

Hello!! Everyone
I am new in the filed of Cortex-M3 and using LPC1343 micro-controller for my project, which also requires a USB HID.
I found USB HID demo in Keil Example folders and by using the USB Stack i created my project, which is exactly similar to example project provided by Keil.

I have to send some data from LPC1343 to PC and from PC to LPC1343, for Sending data from LPC1343->PC In Endpoints are used and for PC->LPC1343 OUT Endpoints are used.

The main Code is as follow:-

// HID Input Report
u8_t InReport;
// HID Output Report
u8_t OutReport;

 // Get HID Input Report -> InReport
void GetInReport (void)
{
  InReport = 0x01;
        return;
}


// Set HID Output Report <- OutReport
void SetOutReport (void)
{
  if(OutReport == 0x01)
        {
                LPC_GPIO1->DATA &= ~(1<<GreenLED);
        }
        else if(OutReport == 0x02)
        {
                LPC_GPIO1->DATA &= ~(1<<BlueLED);
        }
        else
        {
                LPC_GPIO1->DATA |= (1<<GreenLED);
                LPC_GPIO1->DATA |= (1<<BlueLED);
        }
  return;
}

int main()
{
        InitializeSystem();
        USBIOClkConfig();
        // GPIO's Power is enabled by default
        // Set Pins as Output pins.
        LPC_GPIO1->DIR |= (1<<GreenLED);
        LPC_GPIO1->DIR |= (1<<BlueLED);
        // USB Initialzation
        USB_Init();
        // USB Connect
        USB_Connect(TRUE);
        while(1)
        {
    // Do Nothing
        }
}

But as per this code, LPC1343 is sending data continuously to PC, i tried to find the reason behind this, and i found this code in usbuser.c file

/*
 *  USB Endpoint 1 Event Callback
 *   Called automatically on USB Endpoint 1 Event
 *    Parameter:       event
 */

void USB_EndPoint1 (uint32_t event) {

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

I think this code is automatically called after some time and due to this i am getting data on PC
Can any one tell me, how can i send data to PC only at specific changes not continuously.

Call this function, whenever i need to send some data will do my work ( my assumption, haven't tried this), is it right method to do so
USB_WriteEP(HID_EP_IN, &InReport, sizeof(InReport));