cancel
Showing results for 
Search instead for 
Did you mean: 

How to change the uart baudrate dinamically

Posted on January 30, 2018 at 21:53

Hi. I need to change the uart baudrate dinamically.

I have tryied this but sems to not work. Have you got an example to show?

    serial->Init.BaudRate= BaudRate;

    serial->Init.WordLength = UART_WORDLENGTH_8B;

    serial->Init.StopBits = UART_STOPBITS_1;

    serial->Init.Parity = UART_PARITY_NONE;

    serial->Init.Mode = UART_MODE_TX_RX;

    serial->Init.HwFlowCtl = UART_HWCONTROL_NONE;

    serial->Init.OverSampling = UART_OVERSAMPLING_16;

    serial->Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;

    serial->AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;

    HAL_UART_Init(serial);
4 REPLIES 4
Amel NASRI
ST Employee
Posted on January 31, 2018 at 10:49

Hi

Gottardello.Deni

‌,

May I know the STM32 product you are using?

There are some STM32 series where USART automatic baud rate detection is supported and it depends on USART instance.

Have a look to

http://www.st.com/content/ccc/resource/technical/document/application_note/group0/66/fa/62/a2/5c/75/48/a8/DM00327191/files/DM00327pdf/jcr:content/translations/en.DM00327pdf

(STM32 USART automatic baud rate detection) for more details.

-Amel

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Andrew Neil
Evangelist
Posted on January 31, 2018 at 17:44

What do you mean, 'seems not to work'?

What, exactly, does happen?

Posted on January 31, 2018 at 18:32

One must first make sure all data currently being transmitted is flushed.

You can then disable the USART, change the BRR, and then reenable the USART

There is significant opportunity for receive data loss, and you should clear framing, parity or overrun type errors that might be induced.

The HAL structures for USART should have global and long term scope

Changing the rate like this should be sufficient, you could DeInit or disable if it appears not to be.

serial->Init.BaudRate= DifferentBaudRate;

HAL_UART_Init(serial);

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on February 01, 2018 at 21:50

Ok I will try. Regards.