cancel
Showing results for 
Search instead for 
Did you mean: 

Receive A Buffer From UART in FreeRTOS

QuocAn
Associate

Hi, I'm have a trouble with UART Interrupt when using FreeRTOS.

I want to receive a string buffer send from Serial Terminal ( Hercules Software ) using UART interrupt mode. But when I send data, I just receive 2 character. 

Ex: When I send "Resume", I just got echo back 2 line: "Rx_data:R","Rx_data:e".

Has anyone else encountered this problem? Please share a solution with me.

This is my call back function: 

void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
    BaseType_t xHigherPriorityTaskWoken = pdFALSE;

    HAL_UART_Receive_IT(&huart1, &Rx_data, 1);

    if(Rx_data == '\n')
    {
        Rx_buffer[Rx_index] = '\0';

        if(strcmp((char*)Rx_buffer,"Resume") == 0)
        {
            xTaskResumeFromISR(AboveNormalHandle);
        }

        Rx_index = 0;
    }
    else
    {
        if(Rx_index < sizeof(Rx_buffer)-1)
        {
        	printf("Rx_data: %c \n",Rx_data);
            Rx_buffer[Rx_index++] = Rx_data;
        }
    }

    portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
}

 

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Super User

Don't do blocking calls (printf) within an interrupt.

Store everything to a circular buffer and handle in the main thread when you receive the terminating "\n".

If you feel a post has answered your question, please click "Accept as Solution".

View solution in original post

1 REPLY 1
TDK
Super User

Don't do blocking calls (printf) within an interrupt.

Store everything to a circular buffer and handle in the main thread when you receive the terminating "\n".

If you feel a post has answered your question, please click "Accept as Solution".