cancel
Showing results for 
Search instead for 
Did you mean: 

STM32WL30 change USART baud rate

PhilippR
Associate II

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

1 ACCEPTED SOLUTION

Accepted Solutions
PhilippR
Associate II

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!

View solution in original post

6 REPLIES 6
TDK
Super User

 

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".
PhilippR
Associate II

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.


@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.

Depending on the debugger you use, you might be able to set a "data breakpoint".
This is a breakpoint that triggers when a certain data address is accessed. It does not stop at a specific location, but the location that performed the access.

In your case, you would want to monitor for write access to the baudrate register after you had the baudrate set correctly.

The registers are what the peripheral uses. If it's set correctly there, that's what the peripheral will use. There is no shadow register here. Recheck your assumptions. Gotta be missing something.

If you feel a post has answered your question, please click "Accept as Solution".
PhilippR
Associate II

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!