2022-08-17 02:50 AM
Hi!
I try to implement HAL_UART_Receive_IT + UART IDLE way to receive data, because I know maximum size of incoming messages. But i don't know size of each message anyway. To achieve this i do the following things:
1) Initialize UART and enable global UART interrupt
2) Enable UART IDLE interrupt (__HAL_UART_ENABLE_IT(&huart1, UART_IT_IDLE); )
3) Add interrupt IDLE handle into USART1_IRQHandler
void USART1_IRQHandler(void)
if (__HAL_UART_GET_FLAG(&huart1, UART_FLAG_IDLE) == SET)
{
__HAL_UART_CLEAR_IDLEFLAG(&huart1);
///...
HAL_UART_AbortReceive_IT(&huart1);
HAL_UART_Receive_IT(&huart1, (uint8_t*)bRxBuffer, 128);
}
}
///...
}
4) Initialize UART receive at main cycle
//..
HAL_UART_Receive_IT(&huart1, (uint8_t*)bRxBuffer, 128);
//..
As a result, USART IDLE occurs when first symbol recieved, but recieves sequence not finished yet.
What's it may be?
Thank you for attention in advance!