cancel
Showing results for 
Search instead for 
Did you mean: 

Setting Up Clock UART RX TX Baudrate 9600

arduo
Senior

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! 😊

1 ACCEPTED SOLUTION

Accepted Solutions
Tilen MAJERLE
ST Employee

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.

View solution in original post

3 REPLIES 3
Tilen MAJERLE
ST Employee

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.

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

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

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