AnsweredAssumed Answered

STM32F4 Discovery I2S frequency configuration problem

Question asked by em3ly on Nov 4, 2015
Latest reply on Nov 15, 2015 by em3ly
I recently bought a STM32F4 discovery and I'm interested in audio processing. I started trying to record some audio data using the MP45DT02 and the I2S module.
The program is based on the play and record demo, it records the audio data and send it to the pc through usb.
With 16kHz of sample frequency it works but with,for example, 48kHz the generate .wav seems to have noise almost like if there were something wrong with the rcc configuration or i2s sample frequency configuration, **** when the audio is playing to a different frequency that the one that was recorded. Ofcourse I modified the size of pdm and pcm buffers according to datasheet, also I generated a new system_stm32f4xx.c with the excel tool (new PLL configuration). But still does not work.if you could help me, I'd appreciate.
My main.h now looks like this:


#define DECIMATION_FACTOR           64
#define SAMPLE_FREQUENCY                48000
#define OUT_FREQ                          SAMPLE_FREQUENCY/2
#define INPUT_CHANNELS                1
#define PDM_Input_Buffer_SIZE           (OUT_FREQ / 1000 *DECIMATION_FACTOR
                                        * INPUT_CHANNELS/8 )
#define PCM_Output_Buffer_SIZE      (OUT_FREQ / 1000 * INPUT_CHANNELS)
#define Buffer_Input_SIZE                 2048
#define VOLUME                          50


The PDM filter initialization :
Filter.Fs = SAMPLE_FREQUENCY;
Filter.HP_HZ = 10.;
Filter.LP_HZ = (SAMPLE_FREQUENCY / 2.0);
Filter.In_MicChannels = 1;
Filter.Out_MicChannels = 1;
PDM_Filter_Init(&Filter);


The i2s configuration:


SPI_I2S_DeInit(SPI2);
I2S_InitStructure.I2S_AudioFreq = SAMPLE_FREQUENCY * 2;
I2S_InitStructure.I2S_Standard = I2S_Standard_LSB;
I2S_InitStructure.I2S_DataFormat = I2S_DataFormat_16b;
I2S_InitStructure.I2S_CPOL = I2S_CPOL_High;
I2S_InitStructure.I2S_Mode = I2S_Mode_MasterRx;
I2S_InitStructure.I2S_MCLKOutput = I2S_MCLKOutput_Disable;
I2S_Init(SPI2, &I2S_InitStructure);


// Enable the Rx buffer not empty interrupt
SPI_I2S_ITConfig(SPI2, SPI_I2S_IT_RXNE, ENABLE);


And all these are the configurations generated in system_stm32f4xx.c


*-----------------------------------------------------------------------------


System Clock source | PLL (HSE) *-----------------------------------------------------------------------------
SYSCLK(Hz) | 168000000 *-----------------------------------------------------------------------------
HCLK(Hz) | 168000000 *-----------------------------------------------------------------------------
AHB Prescaler | 1 *-----------------------------------------------------------------------------
APB1 Prescaler | 4 *-----------------------------------------------------------------------------
APB2 Prescaler | 2 *-----------------------------------------------------------------------------
HSE Frequency(Hz) | 8000000 *-----------------------------------------------------------------------------
PLL_M | 8 *-----------------------------------------------------------------------------
PLL_N | 336 *-----------------------------------------------------------------------------
PLL_P | 2 *-----------------------------------------------------------------------------
PLL_Q | 7 *-----------------------------------------------------------------------------
PLLI2S_N | 384 *-----------------------------------------------------------------------------
PLLI2S_R | 2 *-----------------------------------------------------------------------------
I2S input clock(Hz) | 192000000
|
To achieve the following I2S config: |
- Master clock output (MCKO): OFF |
- Frame wide : 16bit |
- Audio sampling freq (KHz) : 48 |
- Error % : 0.0000 |
- Prescaler Odd factor (ODD): 1 |
- Linear prescaler (DIV) : 62 | *-----------------------------------------------------------------------------
VDD(V) | 3.3 *-----------------------------------------------------------------------------
Main regulator output voltage | Scale1 mode *-----------------------------------------------------------------------------
Flash Latency(WS) | 5 *-----------------------------------------------------------------------------
Prefetch Buffer | OFF *-----------------------------------------------------------------------------
Instruction cache | ON *-----------------------------------------------------------------------------
Data cache | ON *-----------------------------------------------------------------------------
Require 48MHz for USB OTG FS, | Enabled
SDIO and RNG clock | *-----------------------------------------------------------------------------

Outcomes