cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 I2S Audio Frequency Question

CFran.1
Associate II

Hey guys, I just need some clarification on the I2S Fs real quick, on the STM32F4DISCOV1 board. The formula in the reference manual says, Fs = I2SxClk/((16*2)(2*I2SxDiv + ODD)) or Fs = I2SxClk/((32*2)(2*I2SxDiv + ODD)) for 16 and 32 bit respectively and then if MCLKOE is enabled, then Fs = I2SxClk/[((16*2)(2*I2SxDiv + ODD))*8] or Fs = I2SxClk/[((16*2)(2*I2SxDiv + ODD))*4].

My question is, are these the formulas I still use even if I use mono? Would I still need the 16*2? I also understand the MCLK = Fs * 256.

So using the above formulas, I need one I2S module at 3.072 MHz for a PDM mic and then another I2S module at preferably 24KHz w/(MCLK >= 12MHz (recommended value)) for an audio DAC.

Something I just realized while typing this, I would need a minimum value of 48KHz instead of 24KHz for the audio frequency? Since 48 * 256 = 12.228Mhz. Which means the most I could decimate it by is 64 then? Because 48*64 = 3.072 and the PDM mic rating is only for 1-3.2 Mhz.

But if you use the formula, MCLK disabled. DIV = CLK / (64*Fs). ((3.072*10^3)/(64*48) = 1 and 1 is a forbidden value for the I2S prescalar. I am stuck on how to pick the numbers for the prescalar, I2S PLL, and the Audio frequency.

I feel like I am confusing myself more and more. Any help would be very appreciated!

6 REPLIES 6

> My question is, are these the formulas I still use even if I use mono?

There is no mono in I2S.

Starting the calculation from audion sampling rate is a misleading practice. For the PDM mic, calculate the bit clock frequency (frequency of the I2S_CK pin).

Write down a table with the frequencies you need and the relationships between them - some are fixed, some are given by the registers.

> But if you use the formula, MCLK disabled. DIV = CLK / (64*Fs). ((3.072*10^3)/(64*48) = 1 and 1 is a forbidden value for the I2S prescalar.

As I2S input clock, use a suitable multiple of 12.228MHz.

JW

PS.

> 1 is a forbidden value for the I2S prescalar

Yes it's forbidden by the RM, but appears to work, except that ODD is ignored in that case. However, ST never confirmed this is a working combination so I won't recommend it.

CFran.1
Associate II

Thank you very much for your response! I appreciate it very much. I would like to use the 3.072MHz for a bit clock freq, because it looks like I'll have to use 48KHz and I want to decimate as much as possible so 64 is what i'll do. So because the I2S is stereo, when I sample the mic at 3.072MHz would that mean I'm only getting half that because its expecting a second channel?

The PDM microphone is not I2S, it knows nothing about channels, how could it, the left-right clock a.k.a. I2S_WS is not connected to it.

JW

Wait I think it clicked? So because its two channels I'll be getting 2*16 = 32 bits of data. So I base the mic off of that, which is what you were saying which makes a lot of sense now. So because its 32 bits of data, I can do 96KHz. 32 * 96 = 3.072 Megabits, so 3.072MHz for the mic clock. or I could do 2*32 for 32 bit channel and pick a smaller frequency. Am I correct in saying that if I wanted to do 128 decimation, at 24 KHz that means the bit rate would be 3.072 Megabits. That means (3.072 * 10^6) / 64 = 48KHz. So that means I should pick 96KHz. Then do I just put in the 96KHz into the above formulas to find the I2SxClk, i.e. the PDM mic clock? And then when I play it through the DAC I'll pick 24KHz and then just fill the left and right channel with the mono sound? I feel like I figured it out, thank you so much. Hopefully what i said is correct!

CFran.1
Associate II

Wait correction. Because I want to use 3.072MHz for the mic clock, and I forgot I am stuck at 48KHz that means the max I can use is 64 anyways. So that means the Fs should be 48KHz and then I am assuming I should use that number for the above equations to find the prescalar number and the I2SxClock.

I understand that the WS is not connected to the mic, but I'll be using I2S to communicate with it. That is what the application note recommended. I am just confused on picking the numbers, but I think I figured it out like I stated in another comment. 48KHz at a 64 decimation. So I'll jut choose a I2SxClock that cordinates to that and to the 3.072 MHz for the mic. Thank you for your help and time!