Skip to main content
Associate
Jun 4, 2024 9:19 AM UTC
Question

How to change baud rate of serial port uart in runtime stm32f4?

 

Hi everybody,

I use UART6 of STM32F437 and want to change baud rate between baud rate 115200, 460800 and 921600 in runtime

I've followed some answers from a post here:

https://stackoverflow.com/questions/57283327/how-to-change-the-uart-baud-rate-after-running-on-stm32-board

USART6 -> CR1 &= ~(USART_CR1_UE);

USART6 -> BRR = NEWVALUE;

USART6 -> CR1 |= USART_CR1_UE;

But still can't seem to get the baud rate to change. Has anyone change the baud rate of the UART successful?

/****************************************************/

Thanks and brgs 

This topic has been closed for replies.

5 replies

Andrew Neil
Super User
Jun 4, 2024 9:46 AM UTC

Have you checked the Datasheet and/or Reference Manual ?

https://www.st.com/en/microcontrollers-microprocessors/stm32f437ai.html#documentation

(Product Page doesn't seem to be working for me at the moment)

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
Andrew Neil
Super User
Jun 4, 2024 10:28 AM UTC

Rather than just UE, does it help if you (also) clear TE and/or RE for the change?

 

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
sonminhAuthor
Associate
Jun 5, 2024 4:22 AM UTC

Thanks for your reply

 

Can you talk clearly? Do you have sample code to change baud rate uart runtime

LCE
Principal III
Jun 5, 2024 6:19 AM UTC

As @Andrew Neil said, try to disable TE & RE in CR1 before changing baud rate.

From RM0090:

30.6.3 Baud rate register (USART_BRR)
Note: The baud counters stop counting if the TE or RE bits are disabled respectively.