Hi,
I'm using a UART communication with another device. The incoming string is terminated with "\r\n". All is working well but sometimes it lost some incoming chars. The place where the chars are missed is not at the beginning or end, it is between the whole string. That the incoming answer string is ok I have checked with another serial monitor.
I think that the way I'm using this UART implementation must be the problem.
I use FreeRTOS with a 1ms tick. This one task is responsible for the uart read. With the callback function the incoming data are received and send away with a queue. After this I "reactivat" the UART_read().
char lineBuffer[256];
SemaphoreHandle_t xSemaphoreReadLine = NULL;
void uartRxFinished(UART_Handle handle, void *buf, size_t count)
{
static BaseType_t xHigherPriorityTaskWoken = 0;
// check if a not only \r\n is sent
if(count>1)
{
memcpy(lineBuffer, buf, count);
lineBuffer[count] = 0;
if( xQueueModemRx != 0 )
{
BaseType_t xHigherPriorityTaskWoken;
xHigherPriorityTaskWoken = pdFALSE;
if(count>1){
xQueueSendFromISR( xQueueModemRx, lineBuffer, &xHigherPriorityTaskWoken );
}
if( xHigherPriorityTaskWoken ){
portYIELD_FROM_ISR (xHigherPriorityTaskWoken);
}
}
}
if (xSemaphoreReadLine != NULL)
xSemaphoreGiveFromISR(xSemaphoreReadLine, &xHigherPriorityTaskWoken);
// force rescheduling if the signaled semaphore woke up a higher priorized thread
if (xHigherPriorityTaskWoken){
taskYIELD();
}
}
void uartTxFinished(UART_Handle handle, void *buf, size_t count)
{
}
void *modemTask(void *arg0)
{
UART_Params uartParams;
UART_init();
/* Create a UART with data processing off. */
UART_Params_init(&uartParams);
uartParams.readMode = UART_MODE_CALLBACK;
uartParams.writeMode = UART_MODE_CALLBACK;
uartParams.readDataMode = UART_DATA_TEXT;
uartParams.writeDataMode = UART_DATA_BINARY;
uartParams.readCallback = uartRxFinished;
uartParams.writeCallback = uartTxFinished;
uartParams.readReturnMode = UART_RETURN_NEWLINE;
uartParams.readEcho = UART_ECHO_OFF;
uartParams.baudRate = 115200;
uartParams.dataLength = UART_LEN_8;
uartParams.parityType = UART_PAR_NONE;
uartParams.stopBits = UART_STOP_ONE;
uart = UART_open(Board_UART1, &uartParams);
if (uart == NULL) {
/* UART_open() failed */
while (1);
}
xSemaphoreReadLine = xSemaphoreCreateBinary();
xSemaphoreGive(xSemaphoreReadLine);
xSemaphoreTake(xSemaphoreReadLine, portMAX_DELAY);
UART_read(uart, RxBuf, sizeof(RxBuf));
while (1) {
if( xSemaphoreTake( xSemaphoreReadLine, portMAX_DELAY ) == pdTRUE )
{
/* reactivate receiving data */
UART_read(uart, RxBuf, sizeof(RxBuf));
}
vTaskDelay(10 / portTICK_PERIOD_MS);
}
}
I also tried it with task priority=1 but it doesn't matter.
I'm not really sure if the using of uart_read() function is ok?
