Skip to main content
Vaclav Chrascina
Associate II
May 3, 2018
Question

HAL_UART_STATE remain busy

  • May 3, 2018
  • 3 replies
  • 2436 views
Posted on May 03, 2018 at 16:13

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);

#rs-232 #raw-lwip #stm32f-uart #uart-interrupt
This topic has been closed for replies.

3 replies

waclawek.jan
Super User
May 3, 2018
Posted on May 03, 2018 at 23:04

Error Handler occurs

Why? From where is it called?

JW

Vaclav Chrascina
Associate II
May 4, 2018
Posted on May 04, 2018 at 08:56

Mostly it occurs within this waiting loop after transmission:

            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();   //mostly it occurs here

            }

Aplication seems working fine for some time (I have about 10 valid results), but suddently communication freezes when error handler occurs.

waclawek.jan
Super User
May 6, 2018
Posted on May 06, 2018 at 15:51

I don't use Cube, so don't quite understand what this means, but couldn't this be because the device which is connected through UART does not answer as expected? What's there? Do you monitor the UART Tx and Rx lines, e.g. by a logic analyzer?

JW