cancel
Showing results for 
Search instead for 
Did you mean: 

Audio on STM32F4

lukasz239955_stm1_st
Associate II
Posted on May 25, 2012 at 15:55

Hi guys !

Firstly - hello to everyone ! I have some questions. I am trying to make a project on STM32F407VG that would transfer data from microphone to the headphones through a filter. I am totally new to these topics so until now I was trying to turn onCS43L22 but I think I lack of some information. I would appriciate if you tell me just make a few tips how to work this out. This is what I have now and have no idea if this is right and what to do next :

#include ''stm32f4xx_conf.h''
#include ''stm32f4xx.h''
DAC_InitTypeDef DAC_InitStruct;
I2S_InitTypeDef I2S_InitStruct;
GPIO_InitTypeDef GPIO_InitStruct;
GPIO_InitTypeDef GPIO_InitStructC;
uint8_t rxdata;
void main(void)
{
//RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_25MHz;
GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_PinAFConfig(GPIOB, GPIO_PinSource10,GPIO_AF_SPI2);
GPIO_Init(GPIOB,&GPIO_InitStruct);
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_3;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_25MHz;
GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_PinAFConfig(GPIOB, GPIO_PinSource3,GPIO_AF_SPI2);
GPIO_Init(GPIOC,&GPIO_InitStruct);
I2S_InitStruct.I2S_Mode =I2S_Mode_MasterRx;
I2S_InitStruct.I2S_DataFormat =I2S_DataFormat_16b;
I2S_InitStruct.I2S_MCLKOutput =I2S_MCLKOutput_Enable;
I2S_InitStruct.I2S_AudioFreq =I2S_AudioFreq_44k;
I2S_InitStruct.I2S_CPOL =I2S_CPOL_Low;
RCC_I2SCLKConfig(RCC_I2S2CLKSource_PLLI2S);
I2S_Init(SPI2,&I2S_InitStruct);
//I2S_FullDuplexConfig(I2S2ext,I2S_InitStruct);
I2S_Cmd(SPI2,ENABLE);
while(1){
SPI_I2S_ReceiveData(SPI2);
}
}

And some questions : Do I need to turn on AF function of some pin i.e. I2S2_CK to enable this clock or is it just for scoping if it works through some pin ? Thanks for any help, I'll try to narrow down my problem in the discussion. #cs43l22 #audio
4 REPLIES 4
Posted on May 25, 2012 at 20:18

Do I need to turn on AF function of some pin i.e. I2S2_CK to enable this clock or is it just for scoping if it works through some pin ?

All pins on the interface you want to use must be physically configured, and routed correctly in the AF mux to the peripheral being utilized.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
lukasz239955_stm1_st
Associate II
Posted on May 26, 2012 at 00:10

Yes, I just found out ; )

Ok, so after this I changed everything : ) Ok - next question :

Let's say I have GPIO AF configured, DAC clock enabled, SPI to the mic also and now I want to send data from AIN4A(if I remember it is the input from mic) to the headphone jack. Well, I looked through the datasheets, but could not find any clue. Any thoughts ? 

Thanks : )

raptorhal2
Lead
Posted on May 28, 2012 at 22:01

''SPI to the mic'' ? The mic outputs PDM to the audio chip's AIN4A and B inputs, and to the F4's ADC123_IN13 input.

The CS43L22 data sheet describes I2C communication and the register settings needed for turning on the headphone jack and passing through AIN4A or B signals to the headphone.

Cheers, Hal

lukasz239955_stm1_st
Associate II
Posted on May 30, 2012 at 13:50

SPI to the mic in sense that I connected the clock to the mic. Ok - now I'll try to nail this datasheet. Thanks : ) 

I guess the stm libraries are not very helpful and I'll need to work on registers.