Event lost when sending through the USB to receiver

Hi

I am using stm32f103RBT6 Microcontroller For sending timestamp in millisecond through usb to a receiver . The program works fine when when i am testing in keil uvision before sending through usb but after sending through usb in receiver software it's missing a event (sometime it does lose event and sometimes not). Can anyone please tell me where the problem can be ? the code is too long to pçst here so i can't upload the whole program. Will really appreciate any help. Thanks

Here is the Fifo stack part



typedef struct FifoStack
{
u16 u16EventTimeStampMSPart;    //This variable have only the ms part!!!
u32 u32EventTimeStamp;       // This variable have only the s part!!!
u8 u8EventInput;
} SFIFO_STACK;

// Private function prototypes -------------------------------------------------
void UsbConnect(void);
void StackPush(u32 u32EventTime, u16 u16EventTimeMS, u8 u8Input);
u8 StackPop(SFIFO_STACK *psFifoStack);
void GetMessage(u8 *pu8Buffer);
void TaskFilter(void);

// *****************************************************************************
/// @brief Function that saves an event in cell
/// @fn void StackPush(u32 u32EventTime, u16 u16EventTimeMS, u8 u8Input)
/// @param[in] u32EventTime @brief Event time
/// @param[in] u16EventTimeMS @brief Event time, ms part ASIF
/// @param[in] u8Input @brief Entry number that generated the event
// *****************************************************************************
void StackPush(u32 u32EventTime, u16 u16EventTimeMS, u8 u8Input)
{
if ((s16StackWriteIndex + 1) != s16StackReadIndex)   // checks for stack space
{
sFifo[s16StackWriteIndex].u16EventTimeStampMSPart = u16EventTimeMS;   //saves the time stamp on the stack, part MS

sFifo[s16StackWriteIndex].u32EventTimeStamp = u32EventTime;    // saves the time stamp on the stack

sFifo[s16StackWriteIndex].u8EventInput = u8Input;    //saves the digital input on the stack

s16StackWriteIndex++;    // incrementing the write index

if (s16StackWriteIndex >= STACK_SIZE)   // make circular written index
s16StackWriteIndex = 0;
}
}

// *****************************************************************************
/// @brief Function that retrieves a cell event
/// @fn u8 StackPop(SFIFO_STACK *psFifoStack)
/// @param[out] psFifoStack @brief Event
/// @retval TRUE, se ok
// *****************************************************************************
u8 StackPop(SFIFO_STACK *psFifoStack)
{
if (s16StackReadIndex != s16StackWriteIndex)   // checks for data on the stack
{
psFifoStack->u16EventTimeStampMSPart = sFifo[s16StackReadIndex].u16EventTimeStampMSPart; //search timestamp cell, part MS

psFifoStack->u32EventTimeStamp = sFifo[s16StackReadIndex].u32EventTimeStamp;  // search timestamp cell

psFifoStack->u8EventInput = sFifo[s16StackReadIndex].u8EventInput; // search the digital input cell number

s16StackReadIndex++; // incrementing the read index
if (s16StackReadIndex >= STACK_SIZE) // make the reading rate is circular
s16StackReadIndex = 0;
return TRUE;
}
else
return FALSE;
}

More questions in this forum