2019-03-28 02:57 AM
I know one can enable a UART receive interrupt using
HAL_UART_Receive_IT(&huart2, (uint8_t *)rx_buffer, expectedNumberOfBytes)
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.
2019-03-28 03:56 AM
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....
2019-03-28 04:04 AM
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?
2019-03-28 04:49 AM
It would be a hack...
2019-03-28 04:51 AM
So the best approach would be to Deinit the UART after disabling the interrupt? Hm, guess this is the safest and predictable way.
2019-03-28 10:35 AM
You may need to use HAL_UART_AbortReceive().
This procedure could be used for aborting any ongoing transfer started in Interrupt or DMA mode.