STM32F401 UART

Any bugs you encounter with Flowcode should be discussed here.
Post Reply
Alan_37
Posts: 125
http://meble-kuchenne.info.pl
Joined: Thu Dec 03, 2020 7:23 pm
Has thanked: 37 times
Been thanked: 17 times

STM32F401 UART

Post 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

chipfryer27
Valued Contributor
Posts: 1147
Joined: Thu Dec 03, 2020 10:57 am
Has thanked: 284 times
Been thanked: 412 times

Re: STM32F401 UART

Post 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

Alan_37
Posts: 125
Joined: Thu Dec 03, 2020 7:23 pm
Has thanked: 37 times
Been thanked: 17 times

Re: STM32F401 UART

Post 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

LeighM
Valued Contributor
Posts: 401
Joined: Mon Dec 07, 2020 1:00 pm
Has thanked: 70 times
Been thanked: 217 times

Re: STM32F401 UART

Post 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

Alan_37
Posts: 125
Joined: Thu Dec 03, 2020 7:23 pm
Has thanked: 37 times
Been thanked: 17 times

Re: STM32F401 UART

Post 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

LeighM
Valued Contributor
Posts: 401
Joined: Mon Dec 07, 2020 1:00 pm
Has thanked: 70 times
Been thanked: 217 times

Re: STM32F401 UART

Post 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;

Alan_37
Posts: 125
Joined: Thu Dec 03, 2020 7:23 pm
Has thanked: 37 times
Been thanked: 17 times

Re: STM32F401 UART

Post by Alan_37 »

You'r the best !

Thanks everyone for the quick help

Regards

Alan_37
Posts: 125
Joined: Thu Dec 03, 2020 7:23 pm
Has thanked: 37 times
Been thanked: 17 times

Re: STM32F401 UART

Post 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

LeighM
Valued Contributor
Posts: 401
Joined: Mon Dec 07, 2020 1:00 pm
Has thanked: 70 times
Been thanked: 217 times

Re: STM32F401 UART

Post by LeighM »

Code: Select all

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

Post Reply