AnsweredAssumed Answered

HAL_UART_STATE remain busy

Question asked by Vaclav Chrascina on May 3, 2018
Latest reply on May 6, 2018 by waclawek.jan

Hello,

I am sending requests continuously via TCP/IP using my client application. Requests are send with 200 ms interval.

When a request come I am trying to send request to my peripheral and expect an answer, but sometimes UART remain busy(Error Handler occurs when waiting for HAL_UART_STATE_READY) and communication fail. I would like to ask you if I am doing something wrong. Thank you very much.

 

Here is my function for inquiring result from periph:

 

void Inquire_result (uint8_t TxBuffer[2])
{
    int Timeout = 1000000;
    
    while(huart3.gState != HAL_UART_STATE_READY)                                 
            {
                Timeout--;
                if(Timeout == 0)
                Error_Handler();
            }
            Timeout = 1000000;
            if(HAL_UART_Transmit_IT(&huart3, (uint8_t*)TxBuffer, 2) != HAL_OK)      
            {
                Error_Handler();
            }
            while(huart3.RxState != HAL_UART_STATE_READY)                                       
            {
                Timeout--;
                if(Timeout == 0)
                Error_Handler();
            }
            Timeout = 1000000;
            if(HAL_UART_Receive_IT(&huart3, (uint8_t*)aRxBuffer, 4) != HAL_OK)                 
            {
                Error_Handler();
            }
            while(DataRecieved == 0)                                                       
            {
                Timeout--;
                if(Timeout == 0)
                Error_Handler();
            }
}

 

And here are my callback functions:

 

void HAL_UART_TxCpltCallback(UART_HandleTypeDef *UartHandle)
{
  /* Set transmission flag: transfer complete */
    HAL_GPIO_WritePin(GPIOB,GPIO_PIN_9,GPIO_PIN_RESET);
    DataRecieved = 0;
}

 

void HAL_UART_RxCpltCallback(UART_HandleTypeDef *UartHandle)
{
  /* Set transmission flag: transfer complete */
    HAL_GPIO_WritePin(GPIOB,GPIO_PIN_9,GPIO_PIN_SET);
    DataRecieved = 1;
}

 

And my interrupt priorities:

    /* Ethernet peripheral interrupt init */
    HAL_NVIC_SetPriority(ETH_IRQn, 2, 0);
    HAL_NVIC_EnableIRQ(ETH_IRQn);

 

  /* SysTick_IRQn interrupt configuration */
  HAL_NVIC_SetPriority(SysTick_IRQn, 1, 0);

 

    /* USART3 interrupt Init */
    HAL_NVIC_SetPriority(USART3_IRQn, 0, 0);
    HAL_NVIC_EnableIRQ(USART3_IRQn);

Outcomes