AnsweredAssumed Answered

CubeMX HAL_USART_Receive_IT returning always Noise Error

Question asked by Trackk on Feb 28, 2015
I have checked the demo in:

I setup same configuration following STM32CubeMX and I can Tx but I can't Rx. Instead of calling HAL_UART_RxCpltCallback() on reception it calls HAL_UART_ErrorCallback(). A quick look to the UartHandle->ErrorCode reveals I am getting HAL_UART_ERROR_NE.

However if I go step-by-step on the HAL_UART_IRQHandler() I can see that the Demo code enters this condition:
/* UART in mode Receiver ---------------------------------------------------*/
if((tmp1 != RESET) && (tmp2 != RESET))

But when executing my code it enters this one instead:
  tmp2 = __HAL_UART_GET_IT_SOURCE(huart, UART_IT_TXE);
  /* UART in mode Transmitter ------------------------------------------------*/
  if((tmp1 != RESET) && (tmp2 != RESET))

I even tried changing the configuration mode from UART_MODE_TX_RX to only UART_MODE_RX, but the result is the same.

I am not sending anything and I am only calling the function (which always lights up the blue LED):
if(HAL_UART_Receive_IT(&huart2, (uint8_t *)aRxBuffer, 2)!= HAL_OK){
  } else {

But as soon as a character is received through the port I get the error. The configuration is as follows:
/** System Clock Configuration
void SystemClock_Config(void)
  RCC_OscInitTypeDef RCC_OscInitStruct;
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
  RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  RCC_OscInitStruct.HSICalibrationValue = 6;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
/* USART2 init function */
void MX_USART2_UART_Init(void)
  huart2.Instance = USART2;
  huart2.Init.BaudRate = 9600;
  huart2.Init.WordLength = UART_WORDLENGTH_8B;
  huart2.Init.StopBits = UART_STOPBITS_1;
  huart2.Init.Parity = UART_PARITY_NONE;
  huart2.Init.Mode = UART_MODE_TX_RX;
  huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  huart2.Init.OverSampling = UART_OVERSAMPLING_16;
void MX_GPIO_Init(void)
  GPIO_InitTypeDef GPIO_InitStruct;
  /* GPIO Ports Clock Enable */
  /*Configure GPIO pins : PD12 PD13 PD14 PD15 */
  GPIO_InitStruct.Pin = GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
  HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);

Main program:
int main(void)
  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  /* Configure the system clock */
  /* Initialize all configured peripherals */
    if(HAL_UART_Receive_IT(&huart2, (uint8_t *)aRxBuffer, 2)!= HAL_OK){
    } else {
  while (1)
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *UartHandle)
  HAL_GPIO_TogglePin(GPIOD, LED_GREEN); //Got it
void HAL_UART_ErrorCallback(UART_HandleTypeDef *UartHandle)
  /* Turn LED3 on: Transfer error in reception/transmission process */
  HAL_GPIO_TogglePin(GPIOD, LED_RED); //Error

The reception works fine when using blocking mode HAL_UART_Receive(), but not when using HAL_UART_Receive_IT().