Skip to main content
arduo
Associate III
Jan 10, 2019 10:50 AM UTC
Solved

Setting Up Clock UART RX TX Baudrate 9600

Hi Everyone!

I am using the STM32407IG and i am trying to send data to another mcu chip via USART RX TX Pins.

The Problem is when i run it via USB FS i don't get the baud rate adjusted.

How can i setup the Clock for a Baud rate of 9600?

That's my clock so far:

 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
 RCC_OscInitStruct.HSEState = RCC_HSE_ON;
 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
 RCC_OscInitStruct.PLL.PLLM = 8;
 RCC_OscInitStruct.PLL.PLLN = 192;
 RCC_OscInitStruct.PLL.PLLP = 2;
 RCC_OscInitStruct.PLL.PLLQ = 4;
 HAL_RCC_OscConfig (&RCC_OscInitStruct);

Here i have the baud rate in my code:

 UartHandle.Instance = USARTx;
 UartHandle.Init.BaudRate = 9600;
 UartHandle.Init.WordLength = UART_WORDLENGTH_8B;
 UartHandle.Init.StopBits = UART_STOPBITS_1;
 UartHandle.Init.Parity = UART_PARITY_NONE;
 UartHandle.Init.HwFlowCtl = UART_HWCONTROL_NONE;
 UartHandle.Init.Mode = UART_MODE_TX_RX;
 UartHandle.Init.OverSampling = UART_OVERSAMPLING_16;
	

Thanks for every help! :smiling_face_with_smiling_eyes:

This topic has been closed for replies.
Tilen MAJERLE
Tilen MAJERLEBest answer
ST Employee
Jan 10, 2019 2:17 PM UTC

I see you are using external clock. Please check if HSE_VALUE matches external clock frequency. By default, HSE_VALUE is set to 25000000, as I see from PLLM setting, you are using 8MHz clock, but this is just suspection.

3 replies

Tilen MAJERLE
Tilen MAJERLEBest answer
ST Employee
Jan 10, 2019 2:17 PM UTC

I see you are using external clock. Please check if HSE_VALUE matches external clock frequency. By default, HSE_VALUE is set to 25000000, as I see from PLLM setting, you are using 8MHz clock, but this is just suspection.

Tesla DeLorean
Guru
Jan 10, 2019 2:28 PM UTC

Send an 0x55 pattern repetitively and scope the pin to check the bit-timing.

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
arduo
arduoAuthor
Associate III
Jan 10, 2019 2:47 PM UTC

I used t a example cdc program

PLL_M             = 25

PLL_N             = 336

PLL_P             = 2

PLL_Q             = 7

that was the clock for default and i changed it because the vcp for USB FS doesn't connect with this clock