cancel
Showing results for 
Search instead for 
Did you mean: 

get audio sample from mic and send it to codec

louati-amir
Associate II
Posted on November 22, 2013 at 14:34

Hello,

I wrote this code to test mic and the codec but I don't here any thing :\ If some one can helpe me.

/* config Codec*/
I2S_InitTypeDef I2S_InitStructure; 
GPIO_InitTypeDef GPIO_InitStructure;
/*PLLI2S configure*/
RCC_PLLI2SConfig(271,2);
/*Enable PLLI2S*/
RCC_PLLI2SCmd(ENABLE);
/*Wait PLLI2S Lock*/
while(RESET == RCC_GetFlagStatus(RCC_FLAG_PLLI2SRDY));
/*PLLI2S is I2S clock source*/
RCC_I2SCLKConfig(RCC_I2S2CLKSource_PLLI2S);
/* Enable I2S3 APB1 clock */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI3, ENABLE);
/* Deinitialize SPI2 peripheral */
SPI_I2S_DeInit(SPI3); 
/* I2S2 peripheral configuration */
I2S_InitStructure.I2S_Mode = I2S_Mode_MasterTx;
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_48k;
I2S_InitStructure.I2S_CPOL = I2S_CPOL_Low; 
I2S_Init(SPI3, &I2S_InitStructure);
/* Disable the I2S2 TXE Interrupt */ 
SPI_I2S_ITConfig(SPI3, SPI_I2S_IT_TXE, DISABLE);
/*Pin Configure*/
/* Enable GPIOs clocks */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA |RCC_AHB1Periph_GPIOB | RCC_AHB1Periph_GPIOC, ENABLE);
/* Configure PA15*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
/* Configure PA15*/
GPIO_PinAFConfig(GPIOA, GPIO_PinSource15, GPIO_AF_SPI3);
/* Configure PB3 and PB5*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_5;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
/* Connect PB3 and PB5 I2S3 module*/
GPIO_PinAFConfig(GPIOB, GPIO_PinSource3, GPIO_AF_SPI3);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource5, GPIO_AF_SPI3);
/* Configure PC7 */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOC, &GPIO_InitStructure);
/* Connect PC7 I2S3 module*/
GPIO_PinAFConfig(GPIOC, GPIO_PinSource7, GPIO_AF_SPI3);
/* Enable the SPI2/I2S2 peripheral */
I2S_Cmd(SPI3, ENABLE);
/*end config codec*/
int y = WavePlayerInit(48000);
WavePlayerStart();
while(1) // Don't want to exit
{
//read_data
while(SPI_GetITStatus(SPI2, SPI_I2S_IT_RXNE) != RESET);
data = SPI_I2S_ReceiveData(SPI2);
//send left seid
while(RESET == SPI_I2S_GetFlagStatus(SPI3,SPI_I2S_FLAG_TXE));
SPI_I2S_SendData(SPI3,(data>>8) & 0xFFFF);
while(RESET == SPI_I2S_GetFlagStatus(SPI3,SPI_I2S_FLAG_TXE));
SPI_I2S_SendData(SPI3,(data<<
8
) & 0xFFFF);
//send write seid
while(RESET == SPI_I2S_GetFlagStatus(SPI3,SPI_I2S_FLAG_TXE));
SPI_I2S_SendData(SPI3,(data>>8) & 0xFFFF);
while(RESET == SPI_I2S_GetFlagStatus(SPI3,SPI_I2S_FLAG_TXE));
SPI_I2S_SendData(SPI3,(data<<8) & 0xFFFF);
}

0 REPLIES 0