cancel
Showing results for 
Search instead for 
Did you mean: 

Run-time UART Buadrate change

AP_040
Senior

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.

7 REPLIES 7
saiteja
Associate II

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
Senior

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

Can you give me one sample code for that?

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
Up vote any posts that you find helpful, it shows what's working..
AP_040
Senior

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
Senior

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

turboscrew
Senior III

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
Senior

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

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