cancel
Showing results for 
Search instead for 
Did you mean: 

HSI clock and baudrate ?

antonius
Senior

Dear Members,

I changed my clock from MSI to HSI but my SPI and UART baudrate becoming wrong,

What do I miss here ?

thanks

29 REPLIES 29
antonius
Senior

Please correct my configuration ?

====

void MX_USART3_UART_Init(void)

{

 huart3.Instance = USART3;

   huart3.Instance->BRR=34;

 huart3.Init.BaudRate = 115200;

 huart3.Init.WordLength = UART_WORDLENGTH_8B;

 huart3.Init.StopBits = UART_STOPBITS_1;

 huart3.Init.Parity = UART_PARITY_NONE;

 huart3.Init.Mode = UART_MODE_TX_RX;

 huart3.Init.HwFlowCtl = UART_HWCONTROL_NONE;

 huart3.Init.OverSampling = UART_OVERSAMPLING_8;

 if (HAL_UART_Init(&huart3) != HAL_OK)

 {

   Error_Handler();

 }

}

=====

I read from :

0690X000008A25sQAC.jpg

I would decompose the clocks as seen of the AHB/APB. Print them out a USART that is working. Use the SWV channel if available.

HAL_UART_Init() is going to overwrite the value you put in BBR, and BBR might well be locked when the USART is enabled.

What bit rate do you see if you send 0x55 data patterns? You see anything at the pins?

Assuming the L152, any board we might be familiar with?

Drops into Error_Handler() ?

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

Assuming the L152, any board we might be familiar with?

Nucleo STM32L152RE

Drops into Error_Handler() ?

printf on my Error_Handler ? It's working with uart2, which is talking with GPS, but uart3 not working on a proper speed ??

0x55 pattern to uart3 ? and ping back ?

thanks

antonius
Senior

decomposing ? sounds advance for me, trying to figure it out on implementing it ...

Thanks

baudrate 115200 clock = 2.097Mhz

Send 0x55, code

  printf("0x55");

   printf("\r\n");

output :

0690X000008A2vUQAS.jpg

clock = 32Mhz,

baudrate = 115200

output :

0690X000008A2xkQAC.jpg

any clues ? thanks

antonius
Senior

On STM32CubeMX, it said, UART3 has a conflict, does it matter ?

0690X000008A3otQAC.jpg

while (1) putchar(0x55);​

Use a scope so you can measure bit timing.​

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

Sometime it's easier to check on the datasheet alternate function table.

Anyway only one alternate "output" can be activated (it's a mux) at anytime.

Do check the GPIO registers in debug mode HW register view.

Check on GPIO MODER and AF registers for this pin.

Sorry I don't use CubeMX, what does the Reference Manual suggest are the connectivity modes here, and what pin conflicts are there. As presented you're showing with work with clock source X and failing with clock source Y

So I'd focus on the clock trees and sources, and determine is the clock routing is broken, for example you've selected a source that isn't present, or is at a different frequency.

Outputting a stream of 'U' characters (0x55) gives you something to measure on a scope. ie does something come out of the pin? is it the right frequency?

Try doubling or halving the baud rate you program whilst leaving the terminal at 115200. See data then?

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

Starts by doing simple stuff

Like

 printf("Core=%d, %d MHz\n", SystemCoreClock, SystemCoreClock / 1000000);

 printf("HCLK=%d\n", HAL_RCC_GetHCLKFreq());

 printf("APB1=%d\n", HAL_RCC_GetPCLK1Freq());

 printf("APB2=%d\n", HAL_RCC_GetPCLK2Freq());

Outputting internal clocks via PA8 MCO and scoping them.

And then looking at RCC and peripheral settings in debugger, finding settings in the chain that look/are wrong.

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