2 years, 7 months ago.

Changing baudrate of active UART port.

I have a STM32F746 DISCOVERY board and am trying to figure out how to change the baud rate after being initialized. Unfortunately, after calling the static function RawSerial::baud, the UART port becomes idle and does not transmit the contents of the USART_TDR register.

#include "mbed.h"

RawSerial uartPort(A0, NC);

int main()
        while (true)
               uartPort.printf("Transmit at 9600 - default");


               uartPort.printf("Transmit at 115200");


After running the first baud change, the state of the port goes to idle (logic high) and does not continue. I tried clearing the UE bit in USART_CR1 before changing the baud rate and setting it afterward. The compiler, however, says it does not know the USART_CR1 register. I tried USART4_CR1, USART4->CR1 etc as well.

What am I doing wrong here?

1 Answer

2 years, 7 months ago.

try uartPort.baud(115200); RawSerial::baud(115200) doesn't tell the compiler which uart you want to change the rate of.

Thanks for the suggestion Andy! I changed it, unfortunately with the same effect. I think the Uart needs to be re-initialized. Do you know how to toggle the bits in the CR1 register of the UART4 port?

posted by Alex van Rijs 20 Nov 2018

I've answered your other question directly but I think you just had a USART/UART issue with the naming.

But portObject.baud() should work. I've not used that platform before but that's all you need to do on any of the other mbeds I've used including STM based ones.

posted by Andy A 21 Nov 2018