cancel
Showing results for 
Search instead for 
Did you mean: 

How to recover when there happens uart error

louiey
Associate II

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?

1 ACCEPTED SOLUTION

Accepted Solutions

You'd presumably need to initiate a new HAL_UART_Receive_IT request

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

View solution in original post

2 REPLIES 2

You'd presumably need to initiate a new HAL_UART_Receive_IT request

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Thanks a lot.

It works as I expected.

: )