Skip to main content
CJohn.7
Associate
March 28, 2019
Question

How to disable a STM32 UART interrupt?

  • March 28, 2019
  • 5 replies
  • 5329 views

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.

This topic has been closed for replies.

5 replies

S.Ma
Principal
March 28, 2019

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....

CJohn.7
CJohn.7Author
Associate
March 28, 2019

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
March 28, 2019

It would be a hack...

CJohn.7
CJohn.7Author
Associate
March 28, 2019

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
Associate II
March 28, 2019

You may need to use HAL_UART_AbortReceive().

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