cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L4S5ZIT: USART1,2,3 BRR(Baud Rate) configuration is not changing dynamically

Kmoor
Associate

STM32L4S5ZIT: My code is dynamically changing the AHB prescaler 1 or 2. I am using HSE external 6 MHZ crystal oscillator. So my program dynamically 6 to 3 & 3 to 6 MHZ will be changed through AHB prescaler(I am not using more than 2 prescaler). I am using the 1,2,3 USARTs for serial communications. Whenever i change the system frequency i will reconfigure the USART's BRR value to maintain the 4800 baud rate.

Problem scenario: First time, When i am in 6MHZ i configure the USART for 2400 baud rate 8bit, 2 stop bit & no parity configurations. I am using oversampling 16. In this case the USART is working as expected baudrate.

But when i change the system frequency to 3MHZ, if i reconfigure the USART based on 3MHZ, the USART is not working as expected baud rate of 2400. I can see in debugger the BRR value changed according to baud rate & System frequency. In this case the usart working on 4800 baud rate instead of 2400.

Do you know the reason for this scenario?

1 REPLY 1

Perhaps a prescaler is involved.

You'll likely need to confirm the internal clocking speeds and bus speeds, both externally and looking at what the chip thinks they are.

The USART needs disabling for the BRR to be changed. Does HAL_UART_Init set the right speed or return an error?​

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..