I2S_DMAResume does not Sync in Slave mode. (CubeIDE)
I am using STM32F446 Nuclero and STM32CubeIDE.
I wrote a loopback code from I2S_ADC (PCM1808PWR) to internal DAC.
MCU is slave mode (external clock to IS2_CKIN).
I works fine.
However, when I try to "Pause DMA" and "Resume DMA", I2S of MCU does not sync with PCM1808PWR.
Phenomena is like this;
Sometimes, MCU sync with PCM1808. However (most of the case), those do not sync, and data is mess.
Manual reads, (in HAL_I2S_Receive_DMA section)
"The I2S is kept enabled at the end of transaction to avoid the clock de-synchronization between Master and Slave(example: audio streaming)."
Therefore, I think I can expect MCU will keep in synchronized while Paused.
Or at least, MCU will sync with PCM1808 when it Resumes.
Please help me to avoid the above phenomena.
Thank you for your kind help in advance.
// in main().c
****
HAL_TIM_Base_Start(&htim2) ; // 48kHz timer for DAC start
// Start DAC
if (HAL_DAC_Start_DMA(&hdac, DAC_CHANNEL_1, (uint32_t *) DAC_In, (uint32_t) BLK_SZ*2, DAC_ALIGN_12B_R) != HAL_OK) {
Error_Handler() ;
}
// Start I2S as Slave Receive @48kHz, 24bit in 32bit frame, stereo
if (((I2S_HandleTypeDef *)&hi2s2)->State == HAL_I2S_STATE_READY) {
if (HAL_I2S_Receive_DMA(&hi2s2, (uint16_t*) I2S_ADC_data, (uint16_t) BLK_SZ_IQ_DBL) != HAL_OK) {
// 3rd parameter Size is number of 16bit data in ADC_data even in format 24bit data in 32bit frame (=16bit*2)
Error_Handler();
}
}
HAL_Delay(2000) ;
// above code works well.
while (1) {
if (HAL_I2S_DMAPause(&hi2s2) != HAL_OK) {
Error_Handler();
}
HAL_Delay(5000) ;
if (HAL_I2S_DMAResume(&hi2s2) != HAL_OK) {
Error_Handler();
}
// There is no ERROR, but data is not correct in most of time. (sometimes, it sync and works.)
HAL_Delay(5000) ;
}