2012-08-13 06:06 AM
Hi everybody!
I used external codec ADAU1961 for collect data from two microphones. I used I2S3 simplex mode for receiving data from codec to STM32F4. I configured lines of peripheral I2S3 for transmition (WS - Word Select, CK - Serial Clock, SD - Serial Data). I connected to the codec external master clock MCLK=12.288MHz. I configured codec for sending sound in parameters: fs=48kHz, 2 channels, format data: 16-bit. I2S is configured as slave only for receiving data and codec is configured as master only for sending data. I try to store data in buffer and send it to SD Card. I always receive noise instead of proper probes of sound through I2S3. I have a questions: 1. Need I connect master clock MCLK=12.288MHz also to pin I2S_CKIN mapped on PC9 in STM32F4. 2. How I have to configure pin I2S_CKIN? I configured it as follow: GPIO_InitTypeDef GPIO_InitStructure; RCC_I2SCLKConfig(RCC_I2S2CLKSource_Ext); GPIO_PinAFConfig(GPIOC, GPIO_PinSource9, GPIO_AF_SPI3); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_Init(GPIOC, &GPIO_InitStructure); 3. How can I properly configure I2S3 for receiving data. I filled I2S_InitTypeDef structure as follow: I2S_InitTypeDef I2S_InitStructure; I2S_InitStructure.I2S_AudioFreq = I2S_AudioFreq_48k; I2S_InitStructure.I2S_Standard = I2S_Standard_Phillips; I2S_InitStructure.I2S_MCLKOutput = I2S_MCLKOutput_Disable; I2S_InitStructure.I2S_CPOL = I2S_CPOL_Low; I2S_InitStructure.I2S_DataFormat = I2S_DataFormat_16b; I2S_InitStructure.I2S_Mode = I2S_Mode_SlaveRx; I2S_Init(I2Sx, &I2S_InitStructure); I2S_Cmd(I2Sx, ENABLE); I use polling mode for receiving probes: while (SPI_I2S_GetFlagStatus(SPI3, SPI_FLAG_TXE) == RESET) {} buffer[i] = SPI_I2S_ReceiveData(SPI3); SPI_I2S_ClearFlag(SPI3, SPI_I2S_FLAG_TXE); Could anybody know what I'm doing wrong? Mayby I wrong configure codec ADAU1961? I will be very happy for any suggestions. Best regards! #i2s_ckin #i2s2012-08-13 06:33 AM
I have no experience with using I2S purely as slave, but at least the following is wrong:
> GPIO_PinAFConfig(GPIOC, GPIO_PinSource9, GPIO_AF_SPI3); as I2S_CKIN is at AF5 (i.e. you should've used GPIO_AF_SPI2). It also confuses me that you wrote that the I2S pins are configured for ''transmitting'', while the CODEC is the master (i.e. all 3 pins of the MCU (word clock, bit clock and data)) should be inputs. I also can't quite imagine debugging I2S without an oscilloscope or logic analyzer, which should reveal whether the CODEC is configured properly or no. JW2012-08-14 05:19 AM
2012-08-14 07:44 AM
> It means, that only interface I2S2/SPI2 can accept external clock
No. While it is not absolutely clear from the datasheet, it appears, that both I2S modules have a common clock source, which can be selected from either internal clock from the dedicated I2S PLL, or the external clock through the I2S_CKIN pin. > and works in mode SlaveRx for receiving data from codec? This is even less clear, but I would say that you don't need any clock if you use the I2S modules purely as slave. This would need to be confirmed experimentally, though. JW2012-08-15 02:48 PM
Thanks a lot for information.
So, now I still don't know why I'm receiving wrong data. I consider using oscyloscope for visualing singals on buses. To be sure, could you tell me how I can properly configure peripherial I2S for working in slave receive mode and accept data in format ( fs=48kHz, bits per probe = 16, number of channels = 2(stereo). If you have a time, could you also take a look on datasheet of codec ADAU1961 and mostly on registers which I should configure. I connect two differential micropones on pins LINN LINP and RINP RINN.Best regards!