cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F3xx: I2S master clock

keepcoding
Associate II
Posted on August 12, 2013 at 14:30

Hi

I tried to turn on the master clock for the SPI/I2S bus on the STM32F3 microcontroller by setting the MCLK enable variable in the initialization struct for the I2S 2. But I couldn't get any signal on the PA8 or on the PC6 pin with the alternate function enabled (I2S2_MCK).

Anyone an idea what's wrong?

Thanks
8 REPLIES 8
Posted on August 12, 2013 at 15:57

Anyone an idea what's wrong?

I'd guess, but some code would be illustrative.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
keepcoding
Associate II
Posted on August 12, 2013 at 17:38

RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE);
[...]
I2S_StructInit(&I2S_InitStructure); 
I2S_InitStructure.I2S_Mode = I2S_Mode_SlaveRx; // receive data (-> slave) 
I2S_InitStructure.I2S_Standard = I2S_Standard_MSB;
I2S_InitStructure.I2S_AudioFreq = I2S_AudioFreq_8k;
I2S_InitStructure.I2S_DataFormat = I2S_DataFormat_16b;
I2S_InitStructure.I2S_MCLKOutput = I2S_MCLKOutput_Enable; 
I2S_InitStructure.I2S_CPOL = I2S_CPOL_Low;
SPI_I2S_DeInit(SPI2);
I2S_Init(SPI2, &I2S_InitStructure);
I2S_Cmd(SPI2, ENABLE);
[...]
GPIO_StructInit(&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; 
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOA, &GPIO_InitStructure); 
GPIO_PinAFConfig(GPIOA, GPIO_PinSource8, GPIO_AF_5);

Is this all I need to do to enable the master clock output?
Posted on August 12, 2013 at 18:28

I'd be surprised in being in slave mode is compatible with generating a master clock.

Bit 9 MCKOE: Master clock output enable

 

0: Master clock output is disabled

 

1: Master clock output is enabled

 

Note: This bit should be configured when the I2S is disabled. It is used only when the I2S is in master mode. Not used in SPI mode.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
keepcoding
Associate II
Posted on August 12, 2013 at 19:09

thanks for your reply! ok, but it doesn't make sense to configure the microcontroller as master if it receives data, does it? Is it a bad idea to keep the microcontroller side configured as slave and generate the master clock with a PWM hardware timer?

Posted on August 12, 2013 at 19:35

No, but on the other hand it doesn't make sense that the device sourcing the data isn't providing a suitable clock for it either?

Can't you operate it in a full-duplex mode and just do nothing with the output data?

If you just want a clock then perhaps you can use a timer, or one of the MCOx pins? STM32 parts don't have a fantastic clocking scheme for generating audio frequencies from integer crystal values.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
keepcoding
Associate II
Posted on August 12, 2013 at 20:01

The device sourcing the data is a TI audio codec module which requires an external master clock. I use it to record audio.

MCOx pins? Aren't those fixed at 36 MHz?

I think I will go with a PWM timer. I don't need odd values like 41 kHz, 12 MHz timer will do.

BTW: Where do you find information like 'no master clock output in slave mode'? I find that the datasheet that comes with the device has very limited information...
Posted on August 12, 2013 at 21:29

You'd want to look at the

http://www.st.com/st-web-ui/static/active/en/resource/technical/document/reference_manual/DM00043574.pdf

for the part.

The MCO pin on the F3 should permit you to look at several sources. You could look at HSE, which could be 12 MHz or 12.288 MHz if you picked the right crystal.

12 MHz would also be easy enough to derive from a timer clocking at 72 or 36 MHz

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
keepcoding
Associate II
Posted on August 12, 2013 at 22:28

great! Thanks a lot for your help and the link to the reference manual. I only used the datasheet and the manual for the standard peripheral library up to now...