cancel
Showing results for 
Search instead for 
Did you mean: 

USART2 baud rate coming out 1.5x slower than setting on STM32F4

logan
Associate II
Posted on August 16, 2014 at 04:30

I'm trying to simply send a character over and over to my computer using a USB to TTL adapter and USART2 on the STM32F4 discovery board. I have USART2 configured for 9600 baud which would give 104us bit pulses.

After getting junk characters on the computer, I looked at the TX signal on my scope and saw the bit widths were about 160us, or a baud rate of ~6250 bps. In my program if I set the baud rate to 9600*1.5 I actually get 9600 baud.

All of my reading seems to suggest this is an issue with a clock setting somewhere. Most commonly I see people having an incorrect value of HSE_VALUE. My HSE_VALUE is indeed set to 8000000 for the 8MHz crystal. I also even added -DHSE_VALUE=8000000 into my CFLAGS. Here are some of my other clock settings from system_stm32f4xx.c:

PLL_M: 8

PLL_Q: 7

PLL_N: 336

PLL_P: 2

These all seemed correct to me, but I could be missing something. I'm really at a loss here for what's going on. I'm hoping someone can figure it out. Let me know if you need any additional information. Thanks!

4 REPLIES 4
Posted on August 16, 2014 at 06:42

Use the MCO pin (PA8) and configure it to output internal clocks, and measure those on a scope.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
logan
Associate II
Posted on August 16, 2014 at 09:09

I first added code to the program to output RCC_MCO1Source_HSE. It showed the correct 8 MHz on the scope. I then checked RCC_MCO1Source_PLLCLK on MCO1 and it was 168 MHz.

I also looked at RCC_MCO2Source_SYSCLK with MCO2 and it was 168 MHz also.

Any of these results seem out of the ordinary to you? Thanks.

Posted on August 17, 2014 at 05:11

The maximum output for pins is about 90 MHz, so normally you'd need to divide down the 168 MHz.

Discrepancies between measured and desired baud rates stems from a difference between the actual clock being used, and the value the software believe is being used.

The HSE_VALUE of 25 MHz v 8 MHz typically results in a 1:3.125 distortion, not 1.5, which is more indicative of something running at 12 MHz.

You could print out HSE_VALUE and inspect it's value in various object files.

9600 baud should have a bit time of ~104.2 us
Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
Posted on August 17, 2014 at 05:12

Suggest you attach a complete project for whatever tool chain you are using.

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