Page 1 of 1

STM32F401 UART

Posted: Tue Dec 05, 2023 1:42 am
by Alan_37
Hello ,

I am testing the UART Channel , on STM32f401RC and found the following problems .

1, Setting Custom Baud @ 600 will receive data at 9600
2, Setting the Baud 1200 ( Not Custom ) will receive data at 19200

Clock settings are set ok because @ 2400 and 38400 works fine

Using flowcode V9

Re: STM32F401 UART

Posted: Tue Dec 05, 2023 8:08 am
by chipfryer27
Hi

If you look at this post you will see the calculation Benj shared for baud

viewtopic.php?f=3&t=602&p=3278&hilit=os ... mode#p3278

Although for a PIC I assume the principle is the same for your chip.

Regards

Re: STM32F401 UART

Posted: Tue Dec 05, 2023 9:02 am
by Alan_37
HI good morning and thanks for your reply,

I don't understand what do I have to do, and how this
fixes the Bug in Flowcode.

Also are bugs still being fixed in V9 or just V10 now ?

Regards

Re: STM32F401 UART

Posted: Tue Dec 05, 2023 3:09 pm
by LeighM
The problem here is clocks again :)
To get a baud rate that low you will need to lower the APB2 clock.
Try changing the APB2 prescaler to /4

Re: STM32F401 UART

Posted: Tue Dec 05, 2023 3:50 pm
by Alan_37
Hi,

Yes ! that was the problem works perfectly now

Thank you so much for your help.

By any chance do you know what C code I have to use to change baud rate
need to switch between 600 and 1200 .

Also need to change Parity to even found the following code on the forum
will it work ?


HAL_UART_DeInit(&MX_UART_NUMBER_1);
MX_UART_NUMBER_1.Init.Parity = UART_PARITY_EVEN;
HAL_UART_Init(&MX_UART_NUMBER_1);

Regards

Re: STM32F401 UART

Posted: Tue Dec 05, 2023 4:59 pm
by LeighM
Yes, it should.
And to change the baud rate add this before HAL_UART_Init()

Code: Select all

MX_UART_NUMBER_1.Init.BaudRate = 600;

Re: STM32F401 UART

Posted: Tue Dec 05, 2023 6:18 pm
by Alan_37
You'r the best !

Thanks everyone for the quick help

Regards

Re: STM32F401 UART

Posted: Wed Dec 06, 2023 12:33 am
by Alan_37
Hello , have the last question

Regarding setting UART Parity

For the Even Parity to work UART properties -> Data bits has to be set to 9
so if I want to set the parity back to NO Parity , the data bits has to be set back to
8 , how can I do that within a C code block ?

Thanks

Re: STM32F401 UART

Posted: Wed Dec 06, 2023 10:33 am
by LeighM

Code: Select all

MX_UART_NUMBER_1.Init.WordLength   = UART_WORDLENGTH_9B;
// OR
MX_UART_NUMBER_1.Init.WordLength   = UART_WORDLENGTH_8B;