2013-08-12 05:30 AM
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? Thanks2013-08-12 06:57 AM
Anyone an idea what's wrong?
I'd guess, but some code would be illustrative.2013-08-12 08:38 AM
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?
2013-08-12 09:28 AM
I'd be surprised in being in slave mode is compatible with generating a master clock.
Bit 9 MCKOE: Master clock output enable0: 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.
2013-08-12 10:09 AM
2013-08-12 10:35 AM
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.2013-08-12 11:01 AM
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...2013-08-12 12:29 PM
You'd want to look at the
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 MHz2013-08-12 01:28 PM
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...