2021-07-29 07:27 AM
Hi ,
I am using
HAL_UART_Receive_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size)
HAL api for uart receive interrupt
i am calling it at end of HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
it works for some time
but after some time HAL_UART_Receive_IT return value is Busy
once its busy ,its always busy , i tried below options
if((HAL_UART_Receive_IT(&UartHandle, (uint8_t *)RxBuffer, 1)) != HAL_OK)
{
HAL_UART_Receive_IT(huart, (uint8_t *)RxBuffer, 1) ;
}
2 . I used while loop ,still remains busy forever
if((HAL_UART_Receive_IT(&UartHandle, (uint8_t *)RxBuffer, 1)) != HAL_OK)
{
while(HAL_UART_Receive_IT(huart, (uint8_t *)RxBuffer, 1)==HAL_BUSY);
}
3 . I used timer to ensure a delay after which i try to enable receive interrupt again after 5 sec ,
still remain busy .
4 . I tried running this operation in between __disable_irq() and __enable_irq,still problem remains same.
How to resolve the issue ?
2021-07-29 07:58 AM
The transfer needs to complete in order for it to go from busy to ready. Ensure data is being sent to it. Ensure you're not within an ISR which is blocking it from completing.
2021-07-29 08:15 AM
I used __disable_irq() and __enable_irq also but result remains same
2021-07-29 08:43 AM
2021-07-30 02:40 AM
Check if you are using HAL_UART_Transmit() in polling and HAL_UART_Receive_IT() in inteerupt mode. Use bot Tx and Rx in Interrupt mode. Older ST Driver has shared variables between Tx and Rx.
2021-07-30 03:29 AM
I am using Transmit only ,i will try this
2021-07-30 04:43 AM
How to get newer drivers ?
2021-08-02 05:07 PM
Sounds like a buffer overrun issue most likely due to you being in another interrupt or you're still in the HAL_UART_RxCpltCallback() when another character is received.
Someone had posted in the forums saying after a while when reading a text file that gets updated every so often, that person was looking for a key word. Well that code would not always find the key word. It turns out that person was processing the received data within the interrupt instead of saving the data to a buffer and processing the data from a polling routine outside of the interrupt.
If you are indeed processing the received data within the interrupt, then you should make a ring buffer to save the data and then parse the data outside the interrupt.
2021-08-12 03:44 AM
I am buffering characters till i receive a '\r' inside HAL_UART_RxCpltCallback() function .
an i am calling parser function from inside of HAL_UART_RxCpltCallback() function . Is it OK ?
2021-08-13 03:58 PM
That is why you're having issues. When you're calling another function from within the HAL_UART_RxCpltCallback(), you're no longer receiving interrupts when characters are filling the FIFO, thus you're getting a buffer overrun. You should set a flag that indicates your buffer is ready to be parsed. Then poll outside of any interrupts for that flag and then parse the buffer.