Skip to main content
arduo
Associate III
January 10, 2019
Solved

Setting Up Clock UART RX TX Baudrate 9600

  • January 10, 2019
  • 3 replies
  • 1112 views

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.
Best answer by Tilen MAJERLE

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
January 10, 2019

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
January 10, 2019

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
January 10, 2019

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