cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with I2S in slave mode

jcrepetto
Associate II
Posted on September 15, 2009 at 18:35

Problem with I2S in slave mode

4 REPLIES 4
jcrepetto
Associate II
Posted on May 17, 2011 at 13:23

Hello,

I want to receive data on the I2S2 port of a STM32103ZE, in slave mode. The data in PCM format, long frame sync. The data rate is 8 kHz, and the clock frequency is 256 kHz. Data are 16 bits long, and the packet frames are 32 bits long (See figure 228 of the STM32 ref. manual Rev 09, page 606).

I have configured the inputs PB12 (WS), PB13 (CK) and PB15 (SD) as floating inputs.

Then I have configured the I2S2 peripheral that way :

Code:

RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE); // SPI2 Periph clock enable

I2S_InitStructure.I2S_Mode = I2S_Mode_SlaveRx;

I2S_InitStructure.I2S_Standard = I2S_Standard_PCMLong;

I2S_InitStructure.I2S_DataFormat = I2S_DataFormat_16bextended;

I2S_InitStructure.I2S_MCLKOutput = I2S_MCLKOutput_Disable;

I2S_InitStructure.I2S_AudioFreq = I2S_AudioFreq_8k;

I2S_InitStructure.I2S_CPOL = SPI_CPOL_Low;

I2S_Init(SPI2, &I2S_InitStructure);

I2S_Cmd(SPI2, ENABLE); // Enable SPI2

But there is a problem : data are received, but they are not in sync with the WS signal. For example, if the external device sends data 0xFF00, the STM32 may receive 0x7F8, 0x7F80, 0xFF00, 0xFE00, OxF800, 0x0003, etc ...

The value changes everytime the STM32 is reset.

I have checked that the WS signal is correctly connected to PB12, and that the STM32 can read it (in GPIO mode).

I have probably made a mistake, but where ? May be somebody will see what's wrong ?

Thanks for your help !

maxim2
Associate
Posted on May 17, 2011 at 13:23

Hi,

1) i don't recommend you to use SPI2(I2S2) interface in slave mode. It's more buggy than I2S3(SPI2). To get a bit more detail please read last errata sheet.

2) from my own experience i will say that is important to start master (bit clock, frame) after I2S prepared and enabled for data exchange. Otherwise data could be shifted relative to the frame (WS) signal.

unixoid2003
Associate II
Posted on June 02, 2011 at 09:11

I've almost the same problem on STM32F105.

In i2s2 Slave mode (receive or transmit) PCM (long or short frame sync) 16 bit data/channel, the WS is totally ignored by the chip.

unixoid2003
Associate II
Posted on June 02, 2011 at 16:26

Also in PCM Master mode Datalen=16bit,Chlen=16bit when I2SPR=ODD|140 Fs is 16khz rather than 8 (FS =I2SxCLK / [(16*2)*((2*I2SDIV)+ODD))])

72e6/(16*2*(2*140+1))=8007.1 but not 160xx

I2S bitrate is 256khz - seems to be right (I2S bitrate = number of bits per channel × number of channels × sampling audio frequency)

16*1*16000=256000