cancel
Showing results for 
Search instead for 
Did you mean: 

How to set I2S clock frequency on STM32L151

Posted on October 30, 2015 at 11:00

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);
RCC_PLLCmd(ENABLE);
/* 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_Pin = MICROPHONE_I2S2_SD_PIN | MICROPHONE_I2S2_CLK_PIN ;
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 */
GPIO_PinAFConfig(MICROPHONE_I2S2_PORT, MICROPHONE_I2S2_SD_PIN_SOURCE, GPIO_AF_SPI2);
GPIO_PinAFConfig(MICROPHONE_I2S2_PORT, MICROPHONE_I2S2_CLK_PIN_SOURCE, GPIO_AF_SPI2);
/* I2S peripheral configuration */
SPI_I2S_DeInit(SPI2);
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;
NVIC_Init(&NVIC_InitStructure);
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. #stm32 #stm32l1xx #spi #i2s
0 REPLIES 0