ktownsend wrote on Tuesday, September 22, 2009:
I’m trying to set up a task that will regularly check the rx message queue on uart, and I have the ISR working properly, but whenever I try to read the contents of the rx message queue I receive the character, but the mcu crashes immediately afterwards. Also, if no character is input before xQueuePeek times out (500 ticks in this case) it will also crash. If I remove the code to check the rx queue, it works fine and happily writes to the uart every 100 ticks as expected.
I just ordered the freertos book (hopefully I’ll get it today), but if there something that I’m doing in this task code that I obviously shouldn’t be? (All I’m trying to do it send the char back out to the UART just to see if it works or not.)
static portTASK_FUNCTION(vUART1Task, pvParameters __attribute__((unused)))
{
static xQueueHandle rxQueue = NULL;
uart1GetRxQueue (&rxQueue);
signed portCHAR rxChar;
for (;
{
/* Check if anything is available in the rx queue */
if (rxQueue)
{
if (xQueuePeek(rxQueue, &rxChar, (portTickType)500))
{
/* Print the result on the uart port */
char *feedback;
sprintf(feedback, "Received: %c\r\n", rxChar);
uart1PutString(feedback, 10);
}
}
// Transmit current tick on UART1
char *output;
sprintf(output, "Ticks: %d\r\n", xTaskGetTickCount());
uart1PutString(output, 10);
vTaskDelay(100);
}
}