AnsweredAssumed Answered

How to set I2S clock frequency on STM32L151

Question asked by benjamin.boulet.001 on Oct 30, 2015
Hello everybody,

It's my first post on this forum, I hope it will be helpful.

I've a problem in my I2S configuration on the MCU STM32L151CC.
I connected a microphone mems on this bus (SD & CLK pins) and I need to set a clock around 4 MHz for this mems.
The problem is that the clock max with my setting is 1 MHz.

Here it is my I2S setting :

void I2S2_Configuration(void)
    I2S_InitTypeDef I2S_InitStructure;
    GPIO_InitTypeDef GPIO_InitStructure;
    NVIC_InitTypeDef NVIC_InitStructure;
    //not sure about this
    RCC_PLLConfig(RCC_PLLSource_HSI,  RCC_PLLMul_6, RCC_PLLDiv_3);
    /* Enable SPI2 APB clocks */
    RCC_APB1PeriphClockCmd( RCC_APB1Periph_SPI2, ENABLE );
    /* Enable GPIOB clocks */
    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);
    /* SPI1 Pins configuration */
    /* Configure pins as AF */
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
    GPIO_Init(MICROPHONE_I2S2_PORT, &GPIO_InitStructure); 
    /* Connect pin to Periph */
    /* I2S peripheral configuration */
    I2S_InitStructure.I2S_Standard = I2S_Standard_Phillips;
    I2S_InitStructure.I2S_DataFormat = I2S_DataFormat_16b;
    I2S_InitStructure.I2S_MCLKOutput = I2S_MCLKOutput_Enable;
    I2S_InitStructure.I2S_AudioFreq = I2S_AudioFreq_96k;
    I2S_InitStructure.I2S_CPOL = I2S_CPOL_Low;
    /* I2S Slave Receiver configuration */
    I2S_InitStructure.I2S_Mode = I2S_Mode_MasterRx;
    I2S_Init(SPI2, &I2S_InitStructure);
    /* SPI1 IRQ Channel configuration */
    NVIC_InitStructure.NVIC_IRQChannel = SPI2_IRQn;
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
    I2S_Cmd(SPI2, ENABLE);

When I enter in the I2S_Init function, the line :

/* Get the source clock value: based on System Clock value */
sourceclock = RCC_Clocks.SYSCLK_Frequency;

it returns 32MHz

So I don't understand why I can't reach 4MHz on the clock.