Skip to main content
SimonP
Associate
February 13, 2019
Question

Usart bad baud rate / stop bits setting hanging mcu.

  • February 13, 2019
  • 1 reply
  • 797 views

Hello,

I'm having some issue with the usart, everything works just fine, but if I start querying the usart with a bad baud rate and especially when the stop bits setting is incorrect, then the mcu hangs after couple of seconds. Please look below, I have tried to reset all the flags, but it still has not any positive effect.

void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart) {
 
 if (huart->Instance == USART6) //check if error from MODBUS USART
 {
 
 __HAL_UART_CLEAR_FLAG(&huart6, UART_FLAG_ORE);
 __HAL_UART_CLEAR_FLAG(&huart6, UART_FLAG_FE);
 __HAL_UART_CLEAR_FLAG(&huart6, UART_FLAG_PE);
 __HAL_UART_CLEAR_FLAG(&huart6, UART_FLAG_NE);
 __HAL_UART_CLEAR_FLAG(&huart6, UART_FLAG_RXNE);
 __HAL_UART_CLEAR_FLAG(&huart6, UART_FLAG_TXE);
 
 __HAL_UART_CLEAR_FEFLAG(&huart6);
 __HAL_UART_CLEAR_NEFLAG(&huart6);
 __HAL_UART_CLEAR_OREFLAG(&huart6);
 __HAL_UART_CLEAR_PEFLAG(&huart6);
 __HAL_UART_FLUSH_DRREGISTER(&huart6);
 
 //HAL_DMA_GetError(DMA1_Stream1);
 //HAL_DMA_CleanCallbacks(DMA1_Stream1);
 
 HAL_UART_DMAStop(&huart6);
 HAL_UART_Receive_DMA(&huart6, &MODBUS_Rx_data, 1);
 

​Thanks for any tips,

BR

This topic has been closed for replies.

1 reply

AvaTar
Senior III
February 13, 2019

> ... then the mcu hangs after couple of seconds.

This doesn't happen just so.

Explain what you mean with "hangs". If it hardfaults, check the SCB registers.