cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F4 USART BAUDRATE-Problem

flash86
Associate
Posted on November 19, 2011 at 16:18

Hi Everbody!

I'm trying to set up an USART Connection to my Notebook. Everything works fine but does anyone have a clue why I have to multiply the baudrate-setting with 3 to get the correct baudrate? 

for Example:

   USART_InitStructure.USART_BaudRate = 9600*3;

  USART_InitStructure.USART_WordLength = USART_WordLength_8b;

  USART_InitStructure.USART_StopBits = USART_StopBits_1;

  USART_InitStructure.USART_Parity = USART_Parity_No;

  USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;

  USART_InitStructure.USART_Mode = USART_Mode_Tx;

Attached you can also find the full configuration.

Thanks a lot!

Franz

3 REPLIES 3
Posted on November 19, 2011 at 20:37

Well the clocks are not what you think they are, either HSI/HSE are different (physical vs defined) or the clock setting are getting fouled up.

The code makes a lot of assumptions about the initial content of RCC->CFGR.

Have the part output the clocks via MCO, and check they are what you expect.

One might guess the project thinks HSE_VALUE is 24 or 25 MHz, not the 8 MHz on the STM32F4 Discovery board.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
flash86
Associate
Posted on November 20, 2011 at 12:22

You were right!

the Problem were these lines of code in stm32f4xx.h:

    #if !defined  (HSE_VALUE) 

    #define HSE_VALUE    ((uint32_t)25000000) /*!< Value of the External oscillator in Hz */

    #endif /* HSE_VALUE */

I just redefined it in stm32f4xx_conf.h and now it works perfectly fine!

Thank you!

Posted on November 20, 2011 at 17:06

With Keil/IAR projects this is often stored as a compiler command line option, as a define ''-DHSE_VALUE=8000000''. If you use an existing project/template this is hidden in the metadata, and easily missed if you create a project from scratch.

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