cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 USB library - CDC_Send_DATA()

vicki19880929
Associate III
Posted on September 25, 2013 at 20:09

Hi all,

Currently I'm working on an application that will call CDC_Send_DATA() periodically. However, if I call it too often, some packets will be missing somewhere in the middle.  Does anyone know the reason?  Thanks a lot!

Say, in the following example, it doesn't print out ABCDEFGHI when key is pressed, but only ''DI'', ''EI'', ''FI''... etc.

int main(void)

{

  Set_System();

  Set_USBClock();

  USB_Interrupts_Config();

  USB_Init();

  

  while (1)

  {

    if (bDeviceState == CONFIGURED)

    {

      CDC_Receive_DATA();

      /*Check to see if we have data yet */

      if (Receive_length  != 0)

      {

        if (packet_sent == 1)

{

CDC_Send_DATA ((unsigned char*)''A'',1);

CDC_Send_DATA ((unsigned char*)''B'',1);

CDC_Send_DATA ((unsigned char*)''C'',1);

CDC_Send_DATA ((unsigned char*)''D'',1);

CDC_Send_DATA ((unsigned char*)''E'',1);

CDC_Send_DATA ((unsigned char*)''F'',1);

CDC_Send_DATA ((unsigned char*)''G'',1);

CDC_Send_DATA ((unsigned char*)''H'',1);

CDC_Send_DATA ((unsigned char*)''I'',1);

}

Receive_length = 0;

      }

    }

  }

1 REPLY 1
vicki19880929
Associate III
Posted on September 25, 2013 at 20:29

The problem is solved if I add a delay function between each function call.

But if anyone could somehow explain why, I'd be appreciated! :D