cancel
Showing results for 
Search instead for 
Did you mean: 

How to receive the 24-bit data via I2S

211768963
Associate II
Posted on April 06, 2016 at 11:20

Hi,

I need to get 24bit data via I2S interface from a microphone.It is said on Reference Manual that I need to get the data twice, and 16 bits for each time.Also the 8 LSB should be cleared.

This is my init sequence:

-----------------------------------------------------------------------

static void I2S_Config(void)

{

  I2S_InitTypeDef I2S_InitStructure;

  RCC_I2SCLKConfig(RCC_I2S2CLKSource_PLLI2S);

  RCC_PLLI2SCmd(ENABLE); 

  while(RCC_GetFlagStatus(RCC_FLAG_PLLI2SRDY)); 

  RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI3, ENABLE); 

  I2S_Cmd(SPI3,DISABLE);

  SPI_I2S_DeInit(SPI3);

 

  I2S_InitStructure.I2S_AudioFreq = 3000;

  I2S_InitStructure.I2S_Standard = I2S_Standard_Phillips;

  I2S_InitStructure.I2S_MCLKOutput = I2S_MCLKOutput_Disable; 

  I2S_InitStructure.I2S_CPOL = I2S_CPOL_Low;

  I2S_InitStructure.I2S_DataFormat = I2S_DataFormat_24b; 

  I2S_InitStructure.I2S_Mode = I2S_Mode_MasterRx; 

  I2S_Init(SPI3, &I2S_InitStructure); 

}

-----------------------------------------------------------------------

DMA is used to get the data into the buffer. But the data I received like this:

0x0612

0x847F

The first one is the 16MSB of the 24-bit data, and the second one should be the 16LSB. The 8LSB should

 be zero, but it was not.

I am very confused about this problem.

2 REPLIES 2
Walid FTITI_O
Senior II
Posted on April 06, 2016 at 19:16

Hi zhang.xuru.001,

Try to use the ST' Audio codec and run the Audio_playback_and_record example that you can  find in STM32F4DISCOVERY board firmware package 

http://www.st.com/web/en/catalog/tools/PF257904#

at this path STM32F4-Discovery_FW_V1.1.0\Project\Audio_playback_and_record.

You find related information in the application note

http://www.st.com/web/en/resource/technical/document/application_note/DM00040802.pdf

-Hannibal-

211768963
Associate II
Posted on April 07, 2016 at 04:33

Hi Hannibal,

Thanks for your suggestion. I have read application note and the code before, but the dataformat in ''Audio_playback_and_record'' project is 16-bit. 

If I set the SD pin in pulldown resister mode, most of the 8LSB will be 0x00, and few of them will be 0x80. Maybe it is the result of noise, and the stm32f4 will not clear the 8LSB, instead, it will get the data as normal.