Skip to main content
Associate
September 16, 2025
Solved

STM32WL30 change USART baud rate

  • September 16, 2025
  • 3 replies
  • 442 views

Hello everyone,

I'm working with the STM32WL30 and I'm trying to change the baud rate of the USART peripheral. However, I'm encountering some issues when I change the baud rate.

The function I wrote for changing the baud rate looks like this:

void changeBaudRate(uint16_t baudRate) {
 // start USART reset
 RCC->APB1RSTR |= RCC_APB1RSTR_USARTRST;
 // disable interrupt
 NVIC_DisableIRQ(USART1_IRQn);
 // stop reset
 RCC->APB1RSTR &= ~RCC_APB1RSTR_USARTRST;

 // set BRR
 USART1->BRR = 16000000 / baudRate;
 // set CR1
 USART1->CR1 = USART_CR1_RXNEIE_RXFNEIE | USART_CR1_TE | USART_CR1_RE | USART_CR1_UE;

 // set IR prio
 NVIC_SetPriority(USART1_IRQn, 1);
 // enable IR
 NVIC_EnableIRQ(USART1_IRQn);
}

  

When I configured the baud rate for the first time, everything works fine and I receive the messages. If I change the baudrate to another value, I won't receive messages on the new baud rate, but still with the previously configured baud rate. When I debug the baud rate change, I can see, that the BRR was changed to the new value, but somehow the peripheral still uses the previous BRR value.

 

I also used this logic with a STM32G0 controller without any problems.

 

Thank you in advance for your help!

Best regards,
Philipp

Best answer by PhilippR

I found the problem. The software which I used for testing the USART interface was not working as I expected it to do. So the baud rate of the controller was indeed configured back to the initial value. I modified the test software and now it works fine.

Thanks for your help everyone!

3 replies

TDK
Super User
September 16, 2025

 

Probably a bug in the code somewhere else. The presented code looks fine.

Perhaps log register values to a debug stream so you can verify, or verify in debugging.

"If you feel a post has answered your question, please click ""Accept as Solution""."
PhilippRAuthor
Associate
September 16, 2025

As I said, I already checked it in debugging. The value in the BRR definitly changes, but somehow the peripheral still uses the old configuration.

Andrew Neil
Super User
September 16, 2025

@PhilippR wrote:

The value in the BRR definitely changes, .


Maybe something changes it back ... ?

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.
PhilippRAuthorBest answer
Associate
September 16, 2025

I found the problem. The software which I used for testing the USART interface was not working as I expected it to do. So the baud rate of the controller was indeed configured back to the initial value. I modified the test software and now it works fine.

Thanks for your help everyone!