AnsweredAssumed Answered

I2S doesn't work properly on STM32F407

Question asked by Shkatov.Lev on May 20, 2017
Latest reply on May 22, 2017 by waclawek.jan

I'm trying to launch I2S on STM32F407. Clocks work fine, WS is what I want (8k, 44.1k, etc), CK is 32*WS, MCK is 256*WS. The problem is that data is transfered at a lower speed (twice lower). I.e I send 1000 bytes during 62ms, but it should take 31ms (at 8k sample rate).

Examples of code:

#define WAV_BUFFER_SIZE 1000
uint8_t wavReadBuffer[WAV_BUFFER_SIZE];

 

for(uint16_t i = 0; i < WAV_BUFFER_SIZE; i++){
   wavReadBuffer[i] = 0xff;
}

 

HAL_I2S_Transmit(&hi2s2, (uint16_t*)wavReadBuffer, WAV_BUFFER_SIZE, 5000);

 

static void MX_I2S2_Init(void)
{
   hi2s2.Instance = SPI2;
   hi2s2.Init.Mode = I2S_MODE_MASTER_TX;
   hi2s2.Init.Standard = I2S_STANDARD_MSB;
   hi2s2.Init.DataFormat = I2S_DATAFORMAT_16B;
   hi2s2.Init.MCLKOutput = I2S_MCLKOUTPUT_ENABLE;
   hi2s2.Init.AudioFreq = ((uint32_t)8000U);
   hi2s2.Init.CPOL = I2S_CPOL_LOW;
   hi2s2.Init.ClockSource = I2S_CLOCK_PLL;
   hi2s2.Init.FullDuplexMode = I2S_FULLDUPLEXMODE_DISABLE;
   if (HAL_I2S_Init(&hi2s2) != HAL_OK){Error_Handler();}
}

Outcomes