2013-03-30 02:39 PM
Hello guys,
I have problems trying to interfacing the stm32f4 with the CS43L22 by the I2S protocol. I was able to set up and send the configurations words by I2C and see the handshaking between those with my oscilloscope, but I can't do the same with the I2S prot. So Im pretty sure that there is an error in my code. So please help me!Here is my config code:void I2S_LowLevel_Init(){ GPIO_InitTypeDef GPIO_InitStruct; I2S_InitTypeDef I2S_InitStruct; I2S_StructInit(&I2S_InitStruct); /* Inicializo estructura */ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE); RCC_APB1PeriphResetCmd(RCC_APB1Periph_SPI3, ENABLE); /* CODEC_I2S pins configuration: WS, SCK and SD pins ----------------------------- * I2S3_SCK = PC10 * I2S3_SD = PC12 * I2S3_MCLK = PC7 */ GPIO_InitStruct.GPIO_Pin = GPIO_Pin_7 | GPIO_Pin_10 | GPIO_Pin_12; GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStruct.GPIO_Speed = GPIO_Speed_100MHz; GPIO_InitStruct.GPIO_OType = GPIO_OType_PP; GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOC, &GPIO_InitStruct); /* Connect pins to I2S peripheral */ GPIO_PinAFConfig(GPIOC, GPIO_Pin_7, GPIO_AF_SPI3); GPIO_PinAFConfig(GPIOC, GPIO_Pin_10, GPIO_AF_SPI3); GPIO_PinAFConfig(GPIOC, GPIO_Pin_12, GPIO_AF_SPI3); /*******************************************************************/ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE); GPIO_InitStruct.GPIO_Pin = GPIO_Pin_4; GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStruct.GPIO_Speed = GPIO_Speed_100MHz; GPIO_InitStruct.GPIO_OType = GPIO_OType_PP; GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOA, &GPIO_InitStruct); GPIO_PinAFConfig(GPIOA, GPIO_Pin_4, GPIO_AF_SPI3);//puerto, pines// RCC_PLLI2SCmd(DISABLE);// RCC_I2SCLKConfig(RCC_I2S2CLKSource_PLLI2S);// RCC_PLLI2SCmd(ENABLE);// RCC_GetFlagStatus(RCC_FLAG_PLLI2SRDY); I2S_InitTypeDef I2S_InitType; I2S_InitType.I2S_AudioFreq = I2S_AudioFreq_44k; I2S_InitType.I2S_MCLKOutput = I2S_MCLKOutput_Enable; I2S_InitType.I2S_Mode = I2S_Mode_MasterTx; I2S_InitType.I2S_DataFormat = I2S_DataFormat_16b; I2S_InitType.I2S_Standard = I2S_Standard_Phillips; I2S_InitType.I2S_CPOL = I2S_CPOL_Low; I2S_Init(SPI3, &I2S_InitType); I2S_Cmd(SPI3, ENABLE);}I couldn't configure the I2S3_MCLK pin either. Sorry for my english and thanks for all!Best regards,Bruno #i2s #stm32f4-discovery2013-03-30 04:06 PM
GPIO_PinAFConfig(GPIOC, GPIO_Pin_7, GPIO_AF_SPI3);
These need the PinSource form (an index), rather than the Pin form (a bit mask)2013-03-30 04:54 PM
Thanks clive1, but still not working... I don't know if its a problem with the MCLK config or what, this is the config
void I2S_LowLevel_Init(){ GPIO_InitTypeDef GPIO_InitStruct; I2S_InitTypeDef I2S_InitStruct; I2S_StructInit(&I2S_InitStruct); /* Inicializo estructura */ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE); RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE); RCC_APB1PeriphResetCmd(RCC_APB1Periph_SPI3, ENABLE); /* Connect pins to I2S peripheral */ GPIO_PinAFConfig(GPIOA, GPIO_PinSource4, GPIO_AF_SPI3);//puerto, pines GPIO_PinAFConfig(GPIOC, GPIO_PinSource7, GPIO_AF_SPI3); GPIO_PinAFConfig(GPIOC, GPIO_PinSource10, GPIO_AF_SPI3); GPIO_PinAFConfig(GPIOC, GPIO_PinSource12, GPIO_AF_SPI3); /* CODEC_I2S pins configuration: WS, SCK and SD pins ----------------------------- * I2S3_SCK = PC10 * I2S3_SD = PC12 * I2S3_MCLK = PC7 */ GPIO_InitStruct.GPIO_Pin = GPIO_Pin_7 | GPIO_Pin_10 | GPIO_Pin_12; GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStruct.GPIO_Speed = GPIO_Speed_100MHz; GPIO_InitStruct.GPIO_OType = GPIO_OType_PP; GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOC, &GPIO_InitStruct); /*******************************************************************/ GPIO_InitStruct.GPIO_Pin = GPIO_Pin_4; GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStruct.GPIO_Speed = GPIO_Speed_100MHz; GPIO_InitStruct.GPIO_OType = GPIO_OType_PP; GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOA, &GPIO_InitStruct); I2S_StructInit(&I2S_InitStruct); I2S_InitStruct.I2S_AudioFreq = I2S_AudioFreq_44k; I2S_InitStruct.I2S_MCLKOutput = I2S_MCLKOutput_Enable; I2S_InitStruct.I2S_Mode = I2S_Mode_MasterTx; I2S_InitStruct.I2S_DataFormat = I2S_DataFormat_16b; I2S_InitStruct.I2S_Standard = I2S_Standard_Phillips; I2S_InitStruct.I2S_CPOL = I2S_CPOL_Low; I2S_Init(SPI3, &I2S_InitStruct); I2S_Cmd(SPI3, ENABLE); RCC_PLLI2SCmd(DISABLE); RCC_I2SCLKConfig(RCC_I2S2CLKSource_PLLI2S); RCC_PLLI2SCmd(ENABLE); RCC_GetFlagStatus(RCC_FLAG_PLLI2SRDY);}and in the main code I do: InitGPIO(); I2C_LowLevel_Init(); I2S_LowLevel_Init(); GPIO_WriteBit(GPIOD, GPIO_Pin_4, Bit_RESET); //Reseteo DAC Delay(0x4FFF); GPIO_WriteBit(GPIOD, GPIO_Pin_4, Bit_SET); Codec_Init(); while(1){ SPI_I2S_SendData(SPI3, 0xaaaa); while (SPI_I2S_GetFlagStatus(SPI3, SPI_FLAG_TXE)== RESET); }I don't know if the I2S3_MCK (PC7) is well configured. I think that is not because I can't see nothing in this pin... The value 0xaaaa is just dummy.Thank you again and regards!2013-04-04 02:26 AM
RCC_APB1PeriphResetCmd(RCC_APB1Periph_SPI3, ENABLE);
should beRCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI3, ENABLE); I understand that you've copied this from the ''documentation'' to the ''library'' - well, this is not the only flaw it has. Please let ST know, perhaps through https://my.st.com/onlinesupport/app?page=onlineSupport . JW PS. Clive must have been very tired when looking at this - this is exactly the type of errors he spots immediately... :)