Skip to main content
flash86
Associate
November 19, 2011
Question

STM32F4 USART BAUDRATE-Problem

  • November 19, 2011
  • 3 replies
  • 897 views
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

    This topic has been closed for replies.

    3 replies

    Tesla DeLorean
    Guru
    November 19, 2011
    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 (See Profile) Up vote any posts that you find helpful, it shows what's working..
    flash86
    flash86Author
    Associate
    November 20, 2011
    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!

    Tesla DeLorean
    Guru
    November 20, 2011
    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 (See Profile) Up vote any posts that you find helpful, it shows what's working..