2018-01-03 01:43 PM
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
2018-06-13 02:56 AM
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.2018-06-13 05:25 AM
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