cancel
Showing results for 
Search instead for 
Did you mean: 

STM42F407VG/MB997C I2S3 output silent

flux-ti
Associate II
Posted on September 30, 2014 at 15:27

Hello,

I've been trying to get any life out of the I2S3 output from my STM32 Discovery board, but for some reason I cannot even get a clock signal (CK), as seen with oscilloscope. It also never seems to empty its TX queue: after putting a word in, SPI_I2S_FLAG_TXE is never set. (It is set prior to the first write, though.) I also tried the same with I2S2 (in PC6, PB12,13,15), thinking that perhaps the non-configured audio codec might assert the pins, but with the same results. (Though even with I2S3 the effects have been the same regardless if the device is configured or in reset.) Also I think it's not very likely the audio codec would assert its SDIN.. Here is the self-containing program I've tried. (Mind you, it's not the only one I've tried ;).) Its purpose is to only succeed in sending data over I2S and get some activity in the oscilloscope, but it fails in this (except for the activity during GPIO initialization).

#include ''stm32f4xx_spi.h''
#include ''stm32f4xx_gpio.h''
int
main(
void
)
{
GPIO_InitTypeDef gpio;
// Put audio chip to reset state
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
gpio.GPIO_Pin = GPIO_Pin_4;
gpio.GPIO_Mode = GPIO_Mode_OUT;
gpio.GPIO_OType = GPIO_OType_PP;
gpio.GPIO_PuPd = GPIO_PuPd_NOPULL;
gpio.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOD, &gpio);
GPIO_SetBits(GPIOD, GPIO_Pin_4);
//CS43L22 I2S3 WS(PA4);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
gpio.GPIO_Pin = GPIO_Pin_4;
gpio.GPIO_Mode = GPIO_Mode_AF;
gpio.GPIO_OType = GPIO_OType_PP;
gpio.GPIO_PuPd = GPIO_PuPd_NOPULL;
gpio.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &gpio);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource4, GPIO_AF_SPI3);
//CS43L22 I2S3 MCK(PC7), SCK(PC10), SD(PC12)
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);
gpio.GPIO_Pin = GPIO_Pin_7 | GPIO_Pin_10 | GPIO_Pin_12;
gpio.GPIO_Mode = GPIO_Mode_AF;
gpio.GPIO_OType = GPIO_OType_PP;
gpio.GPIO_PuPd = GPIO_PuPd_NOPULL;
gpio.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_PinAFConfig(GPIOC, GPIO_PinSource7, GPIO_AF_SPI3);
GPIO_PinAFConfig(GPIOC, GPIO_PinSource10, GPIO_AF_SPI3);
GPIO_PinAFConfig(GPIOC, GPIO_PinSource12, GPIO_AF_SPI3);
GPIO_Init(GPIOC, &gpio);
//I2S config
RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI3, ENABLE);
SPI_DeInit(SPI3);
I2S_InitTypeDef i2s;
i2s.I2S_AudioFreq = I2S_AudioFreq_16k;
i2s.I2S_MCLKOutput = I2S_MCLKOutput_Enable;
i2s.I2S_Mode = I2S_Mode_MasterTx;
i2s.I2S_DataFormat = I2S_DataFormat_16b;
i2s.I2S_Standard = I2S_Standard_Phillips;
i2s.I2S_CPOL = I2S_CPOL_Low;
I2S_Init(SPI3, &i2s);
I2S_Cmd(SPI3, ENABLE);
while
(!SPI_I2S_GetFlagStatus(SPI3, SPI_I2S_FLAG_TXE));
SPI_I2S_SendData(SPI3, 42); 
// this line is reached, but no SCK activity
while
(!SPI_I2S_GetFlagStatus(SPI3, SPI_I2S_FLAG_TXE));
while
(1) {
// never reaches this line, no activity on SCK
}
}

I was also thinking that perhaps some of my clocks are misconfigured, but my FreeRTOS test application can do serial communication and switch tasks with timers, so I'm doubtful any mistake there could cause something like this.. I'm happy to receive any help, I've spent a couple days on this, hopefully with something very little to make it work :). Thanks! #discovery #i2s
4 REPLIES 4
flux-ti
Associate II
Posted on September 30, 2014 at 16:54

Seriously, an hour and a half after posting this..

Looking at any possible relevant posts I noticed that the ''STM32F4 SPI3 interrupt problem'' post does

RCC_PLLI2SCmd(ENABLE);

in its initialization sequence. And, sure enough, enabling that started the clock in my oscilloscope and the sends went through fine. Hopefully things will go forward smoothly after this.

This is probably something that is in people's initialization sequences, which is why I had never noticed this earlier? Or was I just being blind :-). Well, now that I knew what to look for, I can see it was mentioned in stm32f4xx_spi.c . Hopefully this information will be useful for someone else :).
Posted on September 30, 2014 at 16:57

Do you configure the PLLI2S in SystemInit() / SetSysClock()? And is that called?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on September 30, 2014 at 16:59

Spooky, crossed on the wire there.

STM32F4xx_DSP_StdPeriph_Lib_V1.3.0\Project\STM32F4xx_StdPeriph_Examples\I2S\I2S_TwoBoards\I2S_DataExchangePolling\system_stm32f4xx.c

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
flux-ti
Associate II
Posted on October 01, 2014 at 09:25

Indeed, my system_stm32f4xx.c did not originate from that project, and it was missing the I2S clock configuration. Thanks for the pointer, I had glossed over that initialization file..