2024-05-19 4:17 AM
This example work perfectly using non interrupt driven UART HAL library, HAL_UART_Receive and HAL_UART_Transmit
Any idea on changing to HAL_UART_Receive_IT and HAL_UART_Transmit_IT?
Many thanks
2024-05-19 4:45 AM
Use ring buffers to hold the data and service the interrupts.
2026-02-20 4:09 PM - last edited on 2026-02-21 1:44 AM by Andrew Neil
Hello ,
You have to do the following ,
1- you have to create Queue, note I use here Queue handler from FreeRTOS for ease but you can implement your own circular buffer
QueueHandle_t xQueueSerial;
char serial_input;
xQueueSerial = xQueueCreate(20,sizeof(serial_input));
2- this queue shall be filled from HAL_UART_RxCpltCallback
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
HAL_UART_Receive_IT(&huart2, (uint8_t*)&serial_input, 1);
xQueueSendFromISR(xQueueSerial,&serial_input,NULL);
}
3- In task you shall check if queue is filled with data, if it is filled then you print the character recieved as following
4- In Task if you press enter '\r' then flag_serial_finished is set to true and now you can parse data using sscanf:
Edited to apply source code formatting; please see How to insert source code for future reference.
Please don't post code as images.