cancel
Showing results for 
Search instead for 
Did you mean: 

HAL_Delay in uart receive interrupt

giwonKIM
Associate III

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);

 

 

}

}

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

HAL_Delay needs SysTicks to keep firing to work.

Make your SysTick interrupt higher priority (numerically lower) than your UART interrupt priority. Like this:

TDK_0-1724290935847.png

 

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.

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

View solution in original post

4 REPLIES 4
TDK
Guru

HAL_Delay needs SysTicks to keep firing to work.

Make your SysTick interrupt higher priority (numerically lower) than your UART interrupt priority. Like this:

TDK_0-1724290935847.png

 

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.

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

Now it works!!

 

Really really thank you.

Nope, it doesn't. It's impossible to do anything practical (like implement any comm protocol) with any Delay() called from a UART ISR.


@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?