9 years, 1 month ago.

UARTs with different baud rate

Hello,

I have a problem with the baud rate of NUCLEO F401RE. The device is connected to UART 2 and sends data at 230500 baud while pc is used for debug via USB with a baud rate 115200. The code below works only if pc and device have the same baud rate.

Can you please help ?

Thank you !

Code

#include "mbed.h"

Serial pc(USBTX, USBRX);
Serial device(PA_9, PA_10);
 
int main() {
  pc.baud (115200);
  device.baud (230400);
  
  while(1) {
        while(device.readable()) {
            pc.putc(device.getc());
        }
  }
}

Question relating to:

Affordable and flexible platform to ease prototyping using a STM32F401RET6 microcontroller.

2 Answers

9 years, 1 month ago.

Hi!

On some devices the UARTS must have the same baud rate! Had this issue on an LPC812 http://developer.mbed.org/platforms/NXP-LPC800-MAX/

I think you have to consult the datasheet for the processor.

Charly

9 years, 1 month ago.

Karl seems to have the right idea! According to the reference manual, it looks like the UARTs share a common baud rate (common clock generator). You can checkout the reference manual here: http://www.st.com/st-web-ui/static/active/en/resource/technical/document/reference_manual/DM00096844.pdf. It's under the "USART" section (section 19).

In general the TX and RX side of a UART must have the same baudrate. The baudrates of different UARTs can in most cases be different. The UART example section that you give above describes a single UARTs registers. The address of the control registers is defined as an offset from a base address (Section 19.6.8: USART register map on page 547). However, each UART has a different baseaddress (see table 1 page 39) and can be set at different baudrates etc. The baudrates are selected by the regeister at offset 8 (USART_BRR) which defines a bitrate division factor in terms of a UART masterclock. You will see in some cases that all UARTs run from the same single masterclock which is in turn derived from the systemclock by some division factor. This may somewhat limit the max and minimum available baudrates. In case there is some link between the baudrates from different Serial objects that may also be the result of some unknown software bug in the mbed lib.

posted by Wim Huiskamp 20 Mar 2015

You're right, I missed that part! I had a feeling I skipped a section :)

So maybe what's going on here is that the selected baud rate (230400) might not be available (due to clock deviders)? I would recommend setting the device to 9600 to see if that works. Otherwise there might be a bigger underlying issue here

posted by Brian Daniels 20 Mar 2015