AnsweredAssumed Answered

STM42F407VG/MB997C I2S3 output silent

Question asked by Erkki Seppälä on Sep 30, 2014
Latest reply on Oct 1, 2014 by Erkki Seppälä
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!

Outcomes