2024-08-21 05:25 PM
Hi
When HAL_Delay goes into uart interrupt, the program stops.
Is there a way to work it out?
I tried to use NVIC, but I don't know how to set it up.
Please advise. Thank you.
Here is my uart interrupt service routine.
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
if(huart == &huart1)
{
uart_receivebuffer[uartidx++] = rx_buf;
if(rx_buf == 0x03)
{
HAL_Delay(100);
UartReceive();
}
HAL_UART_Receive_IT(&huart1, &rx_buf, 1);
}
}
Solved! Go to Solution.
2024-08-21 06:43 PM - edited 2024-08-21 06:43 PM
HAL_Delay needs SysTicks to keep firing to work.
Make your SysTick interrupt higher priority (numerically lower) than your UART interrupt priority. Like this:
It's generally frowned upon to have blocking code, or code that takes a long time to complete, within an interrupt handler, but that is a separate issue.
2024-08-21 06:43 PM - edited 2024-08-21 06:43 PM
HAL_Delay needs SysTicks to keep firing to work.
Make your SysTick interrupt higher priority (numerically lower) than your UART interrupt priority. Like this:
It's generally frowned upon to have blocking code, or code that takes a long time to complete, within an interrupt handler, but that is a separate issue.
2024-08-21 07:23 PM
Now it works!!
Really really thank you.
2024-08-22 12:30 AM
Nope, it doesn't. It's impossible to do anything practical (like implement any comm protocol) with any Delay() called from a UART ISR.
2024-08-22 01:18 AM
@giwonKIM wrote:it works (sic)
It may appear to "work" (sic) in some trivial test case but, as the others have said, it is deeply flawed.
Why do you feel the need to have a delay in your ISR anyhow?