UART HAL Transmission STM32F7 Nucleo

Thread Starter

Xavier Pacheco Paulino

Joined Oct 21, 2015
728
Hi,

I'm trying to understand how to transmit data via UART using the following function.

HAL_UART_Transmit(&huart3, msg , 6 ,1000);
HAL_Delay(500);

This function takes the following parameters:

Parameter 1: &huart3 (It's the handler of the UART 3 on STM32F7 Nucleo)
Parameter 2: msg (It's the data I want to transmit. It's an array of 6 characters)
Parameter 3: 6 (Size of the data)
Parameter 4: 1000 (Timeout)

However, what I don't understand is the timeout. A timeout of 1000 mean 1000 ms = 1 sec. What's the purpose of this parameter?
 

MrChips

Joined Oct 2, 2009
34,807
The UART Transmit and Receive functions use flag polling. These are "blocking" functions, i.e. the processor cannot proceed until the event has been successful. The timeout parameter is the maximum time the processor is allowed to wait while polling a flag. Without this feature the CPU would be hung if the process was never completed.

In the case of the HAL_UART_Transmit( ) it is unlikely that the process would be hung unless there was a catastrophic hardware failure (e.g. the UART clock failed).

In the case of the HAL_UART_Receive( ) it is very possible that the expected number of characters was never received and hence the function would timeout and return to the calling program.
 
Top