cancel
Showing results for 
Search instead for 
Did you mean: 

How to disable a STM32 UART interrupt?

CJohn.7
Associate II

I know one can enable a UART receive interrupt using

HAL_UART_Receive_IT(&huart2, (uint8_t *)rx_buffer, expectedNumberOfBytes)

  • But once started how does one stop it, "manually"?

We can disable the UART interrupt using HAL_NVIC_EnableIRQ . This will prevent it from raising an interrupt, but the state set by the function HAL_UART_Receive_IT which is HAL_UART_STATE_BUSY_RX need to be set back to HAL_UART_STATE_READY for the

UART handle to go back to a state that can accept a new HAL_UART_Receive_ITs.

Question

How to reset the state of the UART interrupt if we wish to disable a Rx interrupt after some time.

5 REPLIES 5
S.Ma
Principal

Well the statr machine in the hal prevents you from directly play with the hw registers and must find a hal function that do so. DeInit might be....

I can deinit and reinit. That works, just looking for a different solution. I've cross posted this question on Stack-Overflow.

I could try reading from the Data register. But still have to manually set the State. Is this the right approach?

S.Ma
Principal

It would be a hack...

So the best approach would be to Deinit the UART after disabling the interrupt? Hm, guess this is the safest and predictable way.

Alex R
Senior

You may need to use HAL_UART_AbortReceive().

This procedure could be used for aborting any ongoing transfer started in Interrupt or DMA mode.