Skip to main content
louiey
Associate II
May 30, 2019
Solved

How to recover when there happens uart error

  • May 30, 2019
  • 1 reply
  • 2856 views

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?

This topic has been closed for replies.
Best answer by Tesla DeLorean

You'd presumably need to initiate a new HAL_UART_Receive_IT request

1 reply

Tesla DeLorean
Tesla DeLoreanBest answer
Guru
May 30, 2019

You'd presumably need to initiate a new HAL_UART_Receive_IT request

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
louiey
louieyAuthor
Associate II
May 30, 2019

Thanks a lot.

It works as I expected.

: )