cancel
Showing results for 
Search instead for 
Did you mean: 

I2S MCLK slew rate issue

d_1
Associate II
Posted on January 22, 2014 at 20:26

Hi,

I've been using an audio codec with the STM32F407 Discovery. Data is transferred using I2S, with the STM32F407 as master.

It generates an MCLK signal at a frequency of 256*fs, i.e at 2.048 MHz for 8 kHz sampling rate and 12.288 MHz for 48 MHz

sampling rate.

So far so good.

But when I tried the same thing on an STM32F401 Discovery (with a processor clock rate of 84 MHz) 48 kHZ sampling wouldn't

work.

I think this is due to the nature of the MCLK signal. Its slew rate is limited and while at 2.048 MHz MCLK appears roughly

square, at 12.288 MHz it appears triangular. In the case of the 168 MHz F407, it rises to around 3 volts in half a period,

in the case of the 84 MHz F401 it rises only to around 2 volts and I think that the codec is not recognising this as a

clock signal.

Is there any way of getting a faster rise time on MCLK?

Here's a very small code snippet -

  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_InitStructure.GPIO_Pin = I2Sx_CK_PIN;

  GPIO_Init(I2Sx_CK_GPIO_PORT, &GPIO_InitStructure);

I've tried different GPIO_Speed settings but they don't appear to have any effect.

Physically disconnecting the MCLK pin (PC6) from the codec and looking at the un-loaded output signal it looks the same.

Thanks for any advice!

#stm32f4 #discovery #i2s
4 REPLIES 4
Posted on January 22, 2014 at 21:26

What kind of scope and probe are you using? Bandwidth?

If you are using a 1x/10x probe make sure to use it in 10x mode.
Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
Posted on January 23, 2014 at 08:48

> I've tried different GPIO_Speed settings but they don't appear to have any effect.

Then you are doing something wrong.

>   GPIO_InitStructure.GPIO_Pin = I2Sx_CK_PIN;

It appears that you are trying to set speed on a different pin, CK, not MCK.

> But when I tried the same thing on an STM32F401 Discovery  [...]

> Physically disconnecting the MCLK pin (PC6) [...]

Are you using the onboard codec of DISCOVERY? If so, it's I2S3, and I2S3_MCK is on PC7.

JW

d_1
Associate II
Posted on January 23, 2014 at 14:54

Clive,

Thanks for your comments. Not for the first, and almost certainly not for the last time, my question

is riven with mistakes and misapprehensions.

I'm using a 50MHz 'scope and at your suggestion I've switched to using a 10x probe. The result is that

the MCLK signals appear much more square, and hence my hypothesis about higher speed MCLKs not getting to the GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;

codec looks incorrect.

I've done a few more tests and, without going into too much detail right now, I have tried to generate an analog

sinusoid from pre-stored samples on the STMF The result is that the program works if I have the statement

I2S_InitStructure.I2S_AudioFreq = I2S_AudioFreq_16k;

but if I change this to

I2S_InitStructure.I2S_AudioFreq = I2S_AudioFreq_44k;

I get a non-sinusoidal analog output.

A difference that I have found is shown in the attached images.

In two cases, I can be pretty sure that I am looking at exactly the same 16-bit data values being written to the codec.

However, at 44kHz something funny has happened and it looks as if the msb has been moved to after the lsb and is

'sticking into' the time slot for the R channel.

The data values in the two cases should be 1110010001100001 dataA and 1101100011110000 dataB

This apparent error has the effect that if the value written is +ve (in the sense of msb = 0) then no problem but if

the value written is -ve (in the sense of msb = 1) then there's a problem.

I can generate a sinusoid at 44kHz sampling rate so long as the data values are in the range 0000000000000000 to

0111111111111

So, I am going to investigate the data formats I'm configuring for and the data types I'm using next

________________

Attachments :

f401_16kHz_dataA.bmp : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006HzzZ&d=%2Fa%2F0X0000000bRr%2F02TbHS66_U_dAQnhE1TGmhfDNLK7UBaqWolhBa5glOs&asPdf=false

f401_16kHz_dataB.bmp : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006HzyX&d=%2Fa%2F0X0000000bRq%2FBvyoeM0iJBApptuytjMnaf3DfCMz5HDTc3c1.4wiYZY&asPdf=false

f401_44kHz_dataA.bmp : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006Hzh9&d=%2Fa%2F0X0000000bRp%2FEWoXRPFiYLBuS_7vOlWpqGJ2uQAcnTYhWPtbyCETDBc&asPdf=false

f401_44kHz_dataB.bmp : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006HzzU&d=%2Fa%2F0X0000000bRo%2Fyyn5GY7niJrLZDB_9QfplE8FwVZ1SBKqE96nxG5OTA8&asPdf=false
d_1
Associate II
Posted on January 23, 2014 at 15:03

Jan,

My snipping was inaccurate - I left in the wrong line of code. In fact I am setting the speed parameter for MCLK. I still can't detect any difference due to changing the GPIO speed.

No, I am not using the on-board DAC.

  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;

  GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_NOPULL;

  GPIO_InitStructure.GPIO_Pin = I2Sx_WS_PIN;

  GPIO_Init(I2Sx_WS_GPIO_PORT, &GPIO_InitStructure);

  GPIO_InitStructure.GPIO_Pin = I2Sx_CK_PIN;

  GPIO_Init(I2Sx_CK_GPIO_PORT, &GPIO_InitStructure);

  GPIO_InitStructure.GPIO_Pin = I2Sx_SD_PIN;

  GPIO_Init(I2Sx_SD_GPIO_PORT, &GPIO_InitStructure);

  GPIO_InitStructure.GPIO_Pin = I2Sx_MCK_PIN;

  GPIO_Init(I2Sx_MCK_GPIO_PORT, &GPIO_InitStructure);

  GPIO_InitStructure.GPIO_Pin = I2Sxext_SD_PIN;

  GPIO_Init(I2Sxext_SD_GPIO_PORT, &GPIO_InitStructure);

Thanks (although problem not yet solved!)

Donald