cancel
Showing results for 
Search instead for 
Did you mean: 

BaudRate in serial port

bmwael1
Associate II
Posted on December 12, 2012 at 15:27

Hi

I've connected my ST32F4 Recovery to PC by USB connection. I create this function to display message to minicom 2.5.

int
PUTC(
int
ch)
{
/* Loop until transmit data register is empty */
while
(USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET);
USART_SendData(USART2, (uint8_t) ch);
return
ch;
}
void
PUTS(
char
*str)
{
char
c;
while
((c = *str++) != 
'\0'
)
PUTC(c);
}

It works because i choose the BaudRate Value = 921600*3.

usart_init.USART_BaudRate = 921600*3;

But if i change this BaudRate it doesn't works.

Do you know why it works only with this value ?

And how it is calculated?

Excuse me for for question but I'm a beginner.

thanks

3 REPLIES 3
Posted on December 12, 2012 at 17:29

Most baud rate issues with STM32 projects occur because of a disagreement between what the HSE physically is, and what HSE_VALUE is defined as in software.

The STM32F4-Discovery has an 8 MHz HSE, other boards, and the presumed default for HSE_VALUE is often 25000000

25/8 = 3.125

Make sure your compiler/toolchain pass in a HSE_VALUE define of 8000000. Make sure that you system_stm32f4xx.c has/uses the appropriate PLL and HSE settings.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
bmwael1
Associate II
Posted on December 13, 2012 at 18:06

Yes exactly

HSE_VALUE 
is
a constant defined 
in
stm32f4xx.h file (
default
value 25 MHz)

HSE Frequency(Hz) = 8000000

I don't understand yet my

BaudRate = 921600*3

= 2

'

764'800 baud

how is it calculated

?

thanks

Posted on December 13, 2012 at 19:08

I'm not sure of you exact situation, or how you are using/testing different baud rates.

The library computes a baud rate divider setting based on internal/external clocks, pll settings, and bus dividers. Having the right HSE_VALUE ensures the math comes up with the right answer.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..