cancel
Showing results for 
Search instead for 
Did you mean: 

Working of RTO (receiver timeout) in UART?

Sdddd
Associate II

Hello,

I have been looking into this RTO flag provided in STM32F303 UART.

According to the manual

"The timeout function and interrupt must be activated, through the RTOEN bit in the USART_CR2 register and the RTOIE in the USART_CR1 register. The value corresponding to a timeout of 2 character times (for example 22 x bit duration) must be programmed in the RTO register. when the receive line is idle for this duration, after the last stop bit is received, an interrupt is generated, informing the software that the current block reception is completed. "

I am running a UART at 115200 baud rate. According to my calculations, one bit duration at this BR is 86 micro seconds (1/115200). To generate an interrupt after 3 sec of no data, I put the value of "34833" in the Receiver timeout register (USART_RTOR).

I sent one char to my uart but the RTO interrupt triggered almost immediately instead of a delay of approx 3 seconds.

Am I doing the calculation wrong? I want to basically generate an interrupt after 3.5 char time of silence but my test so far hasn't helped me understand this feature.

Any help would be appreciated.

1 ACCEPTED SOLUTION

Accepted Solutions

That's about right, if you fire up your calculator again, and consider the difference between bit and byte (frame) time...

> one bit duration at this BR is 86 micro seconds (1/115200)

1/115200 = 8.6805555555555555555555555555556e-6

;)

JW

View solution in original post

10 REPLIES 10

Which STM32F303 exactly, and which USART? The RM says, not all USARTs have this feature.

JW

USART1 on STM32F303RE.

The RTO does time out after a few seconds if I enter a random big value like  USARTx->RTOR = 1000000; (in this RTO interrupt will fire after 8 secs of last sent character) so it seems to be working but I cannot understand the calculation behind it.

That's about right, if you fire up your calculator again, and consider the difference between bit and byte (frame) time...

> one bit duration at this BR is 86 micro seconds (1/115200)

1/115200 = 8.6805555555555555555555555555556e-6

;)

JW

Sdddd
Associate II

omg I am such an idiot. The duration to transmit one bit at 115200 is 8.6 microseconds not 86 micro like i mentioned in my original post.

With the correct value I have to put 345600 in RTO register to timeout after 3 secs and then it works fine.

For interrupt of 3.5 characters silence duration, I'll have to put approx 39 in the register. (3.5 * 11 bits = 38.5).

you're right I just found it a few seconds ago and have been banging my head. Thanks

There are only two kinds of programmers: those who make trivial errors, and those who don't admit it.

JW

BG1
Senior

I know it is an old topic but I need to ask why the character is multiplied by "11" .. I mean where does this 11 come from ? 1 start bit + 8 data bits + 1 stop bit gives 10 bits in total but the eleventh ? Does it come from the sampling bit ? If so , does that vary according to the 8/16 bits sampling method ?

The 11 bits probably refer to either 9 data bits(*) and 1 stop bit, or 8 data bits and 2 stop bits.

JW

[EDIT] (*) That may be 8 data plus one parity plus one stop bit, too. In STM32 UART, 8 data bits plus 1 parity bit is set as 9 bits.

CGemb.1
Associate II

This is all academic, isn't it? I mean that Baud rate is irrelevant to setting RTO. The setting is the number of baud blocks.

/**
  * @brief  Update on the fly the receiver timeout value in RTOR register.
  * @param  huart Pointer to a UART_HandleTypeDef structure that contains
  *                    the configuration information for the specified UART module.
  * @param  TimeoutValue receiver timeout value in number of baud blocks. The timeout
  *                     value must be less or equal to 0x0FFFFFFFF.
  * @retval None
  */
void HAL_UART_ReceiverTimeout_Config(UART_HandleTypeDef *huart, uint32_t TimeoutValue)
{
  assert_param(IS_UART_RECEIVER_TIMEOUT_VALUE(TimeoutValue));
  MODIFY_REG(huart->Instance->RTOR, USART_RTOR_RTO, TimeoutValue);
}

So then, what is a baud block? For a 3 char timeout on 9600-8-n-1, is it the number of characters(3)? Is it the number of bits(3*8)? Is it the number of transitions(3*10)? Is it something else?