cancel
Showing results for 
Search instead for 
Did you mean: 

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

sonminh
Associate II

 

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 

5 REPLIES 5
Andrew Neil
Evangelist III

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)

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

 

Thanks for your reply

 

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

Sorry, no. It was just a suggestion - something for you to try.

LCE
Principal

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.