2019-05-29 06:49 PM
Hello.
I'm using STM32L476RGT and I have a question regarding uart error recovery.
MCU is talk to slave MCU via UART, actually rs485.
Now main MUC is talking to 3 slave MCUs via UART and it's working well but randomly, there happening uart error.
Error code was overrun error so I disabled overrun error at CubeMx tool and this error disappeared but there happening another error, "noise error".
When I get "HAL_UART_ErrorCallback()", I de-initialize uart and initialize again and waiting for next data via uart but it didn't work as I expected, even though uart data coming , there is no interrupt happening.
I use below code when I get error callback.
void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart)
{
uint16_t err = 0;
if(huart->Instance == rs485Port)
{
ERR("485 ERR...%d\n", huart->ErrorCode);
ERR("gState 0x04%x, RxState 0x04%x\n", huart->gState, huart->RxState);
err = huart->Instance->RDR;
err = huart->Instance->ISR;
err = huart->Instance->ICR;
HAL_UART_DeInit(huart);
huart->Instance->CR1 &= 0xFFFE;
huart->Instance->CR1 |= 0x0001;
MX_UART4_Init();
}
}
When there happening uart error, I read DR to empty rx buffer and ISR/ICR to clear flag.
And disable and enable uart enable bit at CR.
But couldn't get uart interrupt even though uart data is coming.
How can I recover uart interrupt when there happen error?
Solved! Go to Solution.
2019-05-29 07:56 PM
You'd presumably need to initiate a new HAL_UART_Receive_IT request
2019-05-29 07:56 PM
You'd presumably need to initiate a new HAL_UART_Receive_IT request
2019-05-30 12:27 AM
Thanks a lot.
It works as I expected.
: )