cancel
Showing results for 
Search instead for 
Did you mean: 

[STM32WB55RG] Usart slave and clock

juvann
Associate III

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?

1 ACCEPTED SOLUTION

Accepted Solutions

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

View solution in original post

3 REPLIES 3
Guenael Cadier
ST Employee

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

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

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