cancel
Showing results for 
Search instead for 
Did you mean: 

NUCLEO-F401RE USART2 weird output on the computer serial tools

RichKnight
Associate II

I used the sample code of "en.stm32cubef4-v1-28-0\STM32Cube_FW_F4_V1.28.0\Projects\STM32F401RE-Nucleo\Examples\UART\UART_Printf"

RichKnight_0-1708019632887.png

I just printed the "test" in the while(1) loop. but the display of my computer is werid, and I checked the clock and hal level code, the clock frequency and data transfer is correct.

there are data tranferred on the serial port. I captured from SB63 test point and use the PICOscope

RichKnight_0-1708021747179.png

 

The USART2 frequency was set to 9600.

RichKnight_2-1708019932071.png

RichKnight_1-1708019899149.png

 

RichKnight_3-1708019972203.png

And I think the USART2 use the APB1 bus frequency: 42MHz

GPIO groupA connected to AHB1.

 

I uploaded the modified code on the github: https://github.com/amazingHH/STM32_UART/tree/main/UART_Printf

I have two boards, and I tested each of them, they have same problem. 

So, is it a USART clock problem?

BTW, I used the KEIL project in the sample code.

1 ACCEPTED SOLUTION

Accepted Solutions
Peter BENSCH
ST Employee

Welcome @RichKnight, to the community!

Well, the number of characters received in the terminal per loop corresponds to the number of characters sent, so you have obviously set the correct baud rate. However, the settings of the receiving terminal are missing and I am quite sure that the usual 8-N-1 was set there, right?

But you are sending with 8-O-1:

UartHandle.Init.BaudRate     = 9600;
UartHandle.Init.WordLength   = UART_WORDLENGTH_8B;
UartHandle.Init.StopBits     = UART_STOPBITS_1;
UartHandle.Init.Parity       = UART_PARITY_ODD; // set it to UART_PARITY_NONE
UartHandle.Init.HwFlowCtl    = UART_HWCONTROL_NONE;
UartHandle.Init.Mode         = UART_MODE_TX_RX;
UartHandle.Init.OverSampling = UART_OVERSAMPLING_16;

Regards
/Peter

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

View solution in original post

4 REPLIES 4
Peter BENSCH
ST Employee

Welcome @RichKnight, to the community!

Well, the number of characters received in the terminal per loop corresponds to the number of characters sent, so you have obviously set the correct baud rate. However, the settings of the receiving terminal are missing and I am quite sure that the usual 8-N-1 was set there, right?

But you are sending with 8-O-1:

UartHandle.Init.BaudRate     = 9600;
UartHandle.Init.WordLength   = UART_WORDLENGTH_8B;
UartHandle.Init.StopBits     = UART_STOPBITS_1;
UartHandle.Init.Parity       = UART_PARITY_ODD; // set it to UART_PARITY_NONE
UartHandle.Init.HwFlowCtl    = UART_HWCONTROL_NONE;
UartHandle.Init.Mode         = UART_MODE_TX_RX;
UartHandle.Init.OverSampling = UART_OVERSAMPLING_16;

Regards
/Peter

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

You're in 7 Bit Odd Parity Mode, is that what you want?

Outputs are not RS232 compatible

Check bit timing with a scope, sending 0x55 'U' repetitively.

Check HSE_VALUE matches that of your design / implementation

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

Thanks, it is really help me!

It fixed! I debuged this whole day!😅

 

Kind Regards

Francois

My Parity Mode was set in wrong mode. 

Thanks for your remind!

I think the sample code use the system clock directly.

 

Kind Regards

Francois