HAL_UART_Receive() always timeout.
Hi all,
I met a strange problem that if I input something via a terminal before I call
HAL_UART_Receive(); It will always timeout. And it will not recover until I reboot the board.
My code is as bellow. What can I do to reset the status? Or enable the interrupt again?
while (1)
{ sprintf(aTxBuffer,'\r\nSTM32CubeMX rocks %d times \t', ++nbtime); HAL_UART_Transmit(&huart2,(uint8_t *) aTxBuffer, strlen(aTxBuffer), 5000);uart_rst = HAL_UART_Receive(&huart2,(uint8_t *) aRxBuffer, 2, 2000);
if(uart_rst==HAL_OK)
{ HAL_UART_Transmit(&huart2,(uint8_t *) str_ack, strlen(str_ack), 5000); } else if(uart_rst==HAL_TIMEOUT) { HAL_UART_Transmit(&huart2,(uint8_t *) str_to, strlen(str_to), 5000); } else { HAL_UART_Transmit(&huart2,(uint8_t *) str_err, strlen(str_err), 5000); } HAL_Delay(2000); /* USER CODE END WHILE *//* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */}
#uart