ksoldavin wrote on Thursday, November 05, 2009:
I am having a problem with a Queue losing the first item stored in it. I am using version 5.4.2 with the dsPIC port. Here is a basic description of my setup. I have a sensor that is transmitting 4304 bytes of data every 5 seconds over a RS-232 port at 57.6k. I have a task that calls SerGetc() to pull a byte from the queue. The byte is then placed in an array. When the array is full I would normally do some analysis.
The first 4304 bytes that are sent are stored correctly and the data looks good. Every data transfer after that is always missing the first byte of data. I have verified that the data is coming over the serial port and is being picked up by the RX ISR. For some reason it is being lost in the queue. Any thoughts? I am out of ideas.
Here is the relevant code:
// This is how I am creating the task and the Queue. They are pulled from my MAIN
xTaskCreate(vSerial_StoreData,( signed portCHAR * )“store data”, 1000, NULL, 1, NULL); // Create the task
xSerialDataIn_1_Queue = xQueueCreate(1000, sizeof(int8)); // Create a receiver Queue for serial 1
// Serial pot 1 receive ISR
void __attribute__((__interrupt__, auto_psv)) _U1RXInterrupt(void)
{
static uint8 newCh = 0;
static uint8 init = 0;
static uint8 output = 0;
static uint16 index = 0;
portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
static portBASE_TYPE result_send;
static portBASE_TYPE result_peek;
IFS0bits.U1RXIF = 0; // Clear the interupt flag
while( U1STAbits.URXDA == 1 )
{
newCh = U1RXREG;
result_send = xQueueSendToBackFromISR( xSerialDataIn_1_Queue, &newCh, &xHigherPriorityTaskWoken );
}
if( xHigherPriorityTaskWoken != pdFALSE )
{
taskYIELD();
}
}
// Gets a single char from Serial port 1. The function will wait, and yield, until a char is available
void Ser1RxGetc(int8 *pc)
{
int8 data = 0;
while (xQueueReceive(xSerialDataIn_1_Queue, &data, 0) == errQUEUE_EMPTY)
taskYIELD();
*pc = data;
}
void vSerial_StoreData (void *pvParameters)
{
uint8 data = 0; // Current data byte
uint16 index = 0; // Byte number received
uint16 count = 0;
uint16 result = 0;
while (1)
{
Ser1RxGetc((int8*)&data); // Grab the data
dataRead = data; // Store the data
if (index < 4304)
{
index++; // Increment the counter
}
else
{
index = 0; // I place break points at thses locations to look at the data
if (count == 0)
result ++;
if (count == 1)
result ++;
if (count == 2)
result ++;
count++;
memset(&dataRead, 0x00, sizeof(dataRead)); // Clear the read buffer
}
}
}