Skip to main content
waclawek.jan
Super User
January 3, 2018
Question

['F446 Cube/documentation] SAIxy_CR1.CKSTR

  • January 3, 2018
  • 1 reply
  • 1280 views
Posted on January 03, 2018 at 22:43

0690X00000609LgQAI.png

For I2S, data are latched on the falling edge of CK (for the transmitter) and are read on the rising

edge (for the receiver). That, according to CKSTR's description above, means to set CKSTR=1 for both transmitter and receiver.

However, [STM32Cube_FW_F4_V1.18.0]\Drivers\STM32F4xx_HAL_Driver\Src\stm32f4xx_hal_sai.c has this to say in HAL_StatusTypeDef SAI_InitI2S():

  /* Compute ClockStrobing according AudioMode */

  if((hsai->Init.AudioMode == SAI_MODEMASTER_TX) || (hsai->Init.AudioMode == SAI_MODESLAVE_TX))

  { /* Transmit */

    hsai->Init.ClockStrobing     = SAI_CLOCKSTROBING_FALLINGEDGE;

  }

  else

  { /* Receive */

    hsai->Init.ClockStrobing     = SAI_CLOCKSTROBING_RISINGEDGE;

  }

So, either the code in Cube, or the description in RM, is wrong.

Which one is it?

JW

    This topic has been closed for replies.

    1 reply

    Technical Moderator
    June 13, 2018
    Posted on June 13, 2018 at 11:56

    Hello

    Waclawek.Jan

    ,

    Since in I2S protocol Data are latched on the falling edge of CK (for transmitter) and are read on the rising edge

    (for the receiver), the corresponding code in Cube is ok and aligned with the reference manual.

    /* Transmit */

    hsai->Init.ClockStrobing = SAI_CLOCKSTROBING_FALLINGEDGE;

    --> ckstr_bits = 1 (refer to HAL_SAI_Init)

    /* Receive */

    hsai->Init.ClockStrobing = SAI_CLOCKSTROBING_RISINGEDGE;

    --> ckstr_bits = 0 (refer to HAL_SAI_Init) In HAL_SAI_Init the code above is used for setting the CKSTR bit:

    /* Compute CKSTR bits of SAI CR1 according to ClockStrobing and AudioMode */

    if((hsai->Init.AudioMode == SAI_MODEMASTER_TX) || (hsai->Init.AudioMode == SAI_MODESLAVE_TX))

    { /* Transmit */

    ckstr_bits = (hsai->Init.ClockStrobing == SAI_CLOCKSTROBING_RISINGEDGE) ? 0U: SAI_xCR1_CKSTR;

    }

    else

    { /* Receive */

    ckstr_bits = (hsai->Init.ClockStrobing == SAI_CLOCKSTROBING_RISINGEDGE) ? SAI_xCR1_CKSTR: 0U;

    }

    Best Regards,

    Imen.

    In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. Thanks
    waclawek.jan
    Super User
    June 13, 2018
    Posted on June 13, 2018 at 12:25

    Oh, I see, so in Cube/HAL you use a different definition of what is 'strobing' than in the RM... This kind of logic is impenetrable for me.

    Thanks for the explanation.

    Jan