Skip to main content
AP_040
Senior
February 27, 2019
Question

Run-time UART Buadrate change

  • February 27, 2019
  • 7 replies
  • 1425 views

I am working on STM32L462CE MCU and my requirement is to change the baudrate of UART at run-time. So, how I do that?. Can you please give me the solution for this. First set to 9600bps, after 921600 and at last 115200.

This topic has been closed for replies.

7 replies

saiteja
Associate III
February 27, 2019

First make sure all data currently being transmitted is completed i.e checking status of TXE and TC

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

AP_040
AP_040Author
Senior
February 27, 2019

Thanks for your reply !!! @Community member​ .

Can you give me one sample code for that?

Tesla DeLorean
Guru
February 27, 2019

I think this was covered within the last month.

Spin on TC/TXE to confirm pending data has transited. ie ready to take more, the previous stuff completed.

Call HAL_UART_Init() with the an updated baud rate field.

Not super difficult. Couple of minutes effort.

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
AP_040
AP_040Author
Senior
February 27, 2019

I tested it and give me the status zero.

MX_UART4_Init_9600(); // baudrate 9600

G3_Baudrate_set(); // send cmd to other chip

uint8_t status = LL_USART_IsActiveFlag_TC(&huart4);

printf("stauts = %x\r\n",status);

HAL_UART_DeInit(&huart4); //uart de-init

MX_UART4_Init_921600(); //set the baud rate 921600

Still UART initialization failed.

AP_040
AP_040Author
Senior
March 5, 2019

Can somebody help on this? How UART baudrate changed at run-time?.

turboscrew
Senior III
March 5, 2019

What's this "G3_Baudrate_set(); // send cmd to other chip"?

Are you trying to ghange the other end baudrate AFTER you change your end's?

AP_040
AP_040Author
Senior
March 5, 2019

It just a command for baudrate change request to the other connected chip with UART .

My requirement is to set baudrate 9600 -> 912600 -> 115200.