cancel
Showing results for 
Search instead for 
Did you mean: 

UART_HandleTypeDef and auto baudrate

In auto baud rate situation is there a way to know the actual baud rate of the uart, anthe the other parameters linke size and parity?

huart1->Init.BaudRate

seems to have the initial parameters but not the actuals.

4 REPLIES 4
Bob S
Principal

After checking the ABRF flag in the ISR register to see that the auto-baud has finished, read the BRR (huart1.Instance->BRR) which should have the results of the auto-baud measurement. To get the actual baud rate you need to know your UART clock frequency and reverse the normal baud rate equation to solve for baud rate given clock freq and divisor.

Many thanks, it works.

The auto baudrate works only one time from the startup. My situation it is different because the baud rate can change at runtime.

So I have implemented the uart reconfiguration each second to re enable the auto baudrate.

Do you think could be problems or can you suggest me another way?

Bob S
Principal

According to the reference manual (at least for the STM32L4xx, at the end of the "USART auto baud rate detection" section), once you have enabled auto baud rate and gone through the first auto sequence, you can re-start the auto baud sequence by clearing the ABRF flag (as long as the ABREN bit is still set to enable the auto-baud feature). You'll need to look at the HAL code, or look at the UART registers themselves after the first auto-baud sequence to see if the HAL code keeps it enabled or not.

Many thanks for the explanation.

Now I'm trying and there is a problem.

The auto baud rate feature does not work if the first byte is 0x02. It work if I send for example "aa" (0x6161). It is very strange.

The main problem is: I have to attach a 485 bus at the uart of a Raspberry Pi.

In order to manage the 485 enable signal my idea is to use a external micro.

I don't know which speed and which software will use the bus so the micro has to switch automatically the baud rate. Is it possible?