Skip to main content
juvann
Associate III
January 19, 2023
Solved

[STM32WB55RG] Usart slave and clock

  • January 19, 2023
  • 1 reply
  • 1742 views

I have a board P-Nucleo55WB and I have to receive data from usart syncronized with external clock.

Is it possible?

I tried to configure with CubeMX as Syncronized Slave and I see USART1_CK enabled, but this pin is not used for receive the external clock, is it correct?

In the generated code I see this

 /*-------------------------- USART BRR Configuration -----------------------*/
 /* BRR is filled-up according to OVER8 bit setting which is forced to 1 */
 USART_GETCLOCKSOURCE(husart, clocksource);
 
 switch (clocksource)
 {
 case USART_CLOCKSOURCE_PCLK2:
 pclk = HAL_RCC_GetPCLK2Freq();
 usartdiv = (uint32_t)(USART_DIV_SAMPLING8(pclk, husart->Init.BaudRate, husart->Init.ClockPrescaler));
 break;
 case USART_CLOCKSOURCE_HSI:
 usartdiv = (uint32_t)(USART_DIV_SAMPLING8(HSI_VALUE, husart->Init.BaudRate, husart->Init.ClockPrescaler));
 break;
 case USART_CLOCKSOURCE_SYSCLK:
 pclk = HAL_RCC_GetSysClockFreq();
 usartdiv = (uint32_t)(USART_DIV_SAMPLING8(pclk, husart->Init.BaudRate, husart->Init.ClockPrescaler));
 break;
 case USART_CLOCKSOURCE_LSE:
 usartdiv = (uint32_t)(USART_DIV_SAMPLING8(LSE_VALUE, husart->Init.BaudRate, husart->Init.ClockPrescaler));
 break;
 default:
 ret = HAL_ERROR;
 break;
 }

so clock source can not be external, what is the function of the USART1_CK GPIO?

This topic has been closed for replies.
Best answer by Guenael Cadier

Hi @juvann​ 

When operating in Slave mode, the Clock will be provided by the device you are connected to (i.e. the remote side operating as Master). So the baudrate setting on slave side will not be taken into account (you could leave a default value as 9600 in your CubeMx configuration, but it will not be used).

Regards

1 reply

Guenael Cadier
ST Employee
January 20, 2023

Hi @juvann​ 

In Synchronous mode, if USART is configured in Slave mode, USARTx_CK is pin is the input of the USART. It should then be connected to CK pin of the Master.

Regards

juvann
juvannAuthor
Associate III
January 21, 2023

Hi @Guenael Cadier​ ,

thank you for your reply.

Why in the code generated by CubeMx the source code can't be external?

How should I configure the baudrate when the clock is external?

Maybe is better remove a part of generate code and set uart div manually.

Regards

Guenael Cadier
Guenael CadierBest answer
ST Employee
January 23, 2023

Hi @juvann​ 

When operating in Slave mode, the Clock will be provided by the device you are connected to (i.e. the remote side operating as Master). So the baudrate setting on slave side will not be taken into account (you could leave a default value as 9600 in your CubeMx configuration, but it will not be used).

Regards