cancel
Showing results for 
Search instead for 
Did you mean: 

STM32H753BIT6: UART Asynchronous Receive with Timeout

Rajeev Arora
Senior

Hello,

I am using below function to receive data asynchronously (Full-Duplex) over USART1 RX

__schedule_barrier();
 
		if(HAL_OK != HAL_UART_Receive_IT(&huart1, (uint8_t *)ucTestKey, 1))
		{
			dLEDShowError(dUSART1RxInitiationFailed);
			assert_failed((uint8_t *)__FILE__, __LINE__);
		}
 
		__schedule_barrier();
 
		while (HAL_UART_STATE_READY != HAL_UART_GetState(&huart1))
		{
			__NOP();
		}
 
		__schedule_barrier();
 
// The variable is set inside UART1 interrupt after reception of data
		while(dRxInProgress == bIsAsyncUSART1ReceiveComplete)
		{
			__NOP();
		}

I am unable to find a way to come out of Receive interrupt when data is not received over USART1 RX even after few milliseconds (say for 0.1 seconds).

I even tried adding code just after the comment

/* USER CODE BEGIN USART1_Init 2 */

present inside function

MX_USART1_UART_Init()

The added code is:

SET_BIT(huart1.Instance->CR1, USART_CR1_RTOIE);
 
if(IS_UART_RECEIVER_TIMEOUT_VALUE(dUSART1ReceiveTimeoutInBitsCount))
{
	HAL_UART_ReceiverTimeout_Config(&huart1, 2);// #DRA: modified for testing: earlier value was dUSART1ReceiveTimeoutInBitsCount
	HAL_UART_EnableReceiverTimeout(&huart1);
}
else
{
	dLEDShowError(dUSART1RxTimeoutTooLarge);
}
 

When above did not help with timeout (and did not result in execution of USART1 IRQ function), I added below:

HAL_UART_ReceiverTimeout_Config(&huart1, 3);

before HAL_UART_Receive_IT().

Above also did not help.

I also observe that the output / return value of function HAL_UART_GetState(&huart1) does not have bits [7:6] set to 10.

Reason:
 
 * @brief HAL UART State definition
 * @note HAL UART State value is a combination of 2 different substates: gState and RxState (see @ref UART_State_Definition).
 *    - gState contains UART state information related to global Handle management
 *     and also information related to Tx operations.
 *     gState value coding follow below described bitmap :
 *     b7-b6 Error information
 *       00 : No Error
 *       01 : (Not Used)
 *       10 : Timeout
 *       11 : Error
 *    b5     Peripheral initialization status
 *        0  : Reset (Peripheral not initialized)
 *        1  : Init done (Peripheral not initialized. HAL UART Init function already called)
I assume "Peripheral not initialized" should be replaced with "Peripheral initialized" in both gState and RxState related comments.

Please suggest which functions to call to know that "no bytes have been received over RX" (for a finite duration).

Thanks,

Rajeev

1 REPLY 1
Rajeev Arora
Senior

Currently the USART 1 is setup in Master mode, asynchronous communication with

115200 bps, 8-N-1