stm32f4 的I2S 全双工

2020-01-04 18:59发布

本帖最后由 dreamc 于 2014-7-14 23:25 编辑

GPIO Init
  1.           GPIO_InitTypeDef GPIO_InitStructure;
  2.           RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
  3.           RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);
  4.           RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
  5.           GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_13 |GPIO_Pin_14  | GPIO_Pin_15;//WS CK SD
  6.           GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  7.           GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  8.           GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  9.           GPIO_InitStructure.GPIO_PuPd =  GPIO_PuPd_NOPULL;
  10.           GPIO_Init(GPIOB, &GPIO_InitStructure);
  11.           GPIO_PinAFConfig(GPIOB, GPIO_PinSource12, GPIO_AF_SPI2);  
  12.           GPIO_PinAFConfig(GPIOB, GPIO_PinSource13, GPIO_AF_SPI2);
  13.           GPIO_PinAFConfig(GPIOB, GPIO_PinSource15, GPIO_AF_SPI2);
  14.     GPIO_PinAFConfig(GPIOB, GPIO_PinSource14, GPIO_AF_I2S2ext);
  15.        
  16.           GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; //MCLK
  17.           GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  18.           GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  19.           GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  20.           GPIO_InitStructure.GPIO_PuPd =  GPIO_PuPd_NOPULL;
  21.           GPIO_Init(GPIOC, &GPIO_InitStructure);   
  22.           GPIO_PinAFConfig(GPIOC, GPIO_PinSource6, GPIO_AF_SPI2);
复制代码

I2S Init
  1.           I2S_InitTypeDef I2S_InitStructure;
  2.           RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE);
  3.           SPI_I2S_DeInit(SPI2);
  4.        
  5.           I2S_StructInit(&I2S_InitStructure);
  6.           I2S_InitStructure.I2S_AudioFreq = I2S_AudioFreq_8k;;
  7.           I2S_InitStructure.I2S_Standard = I2S_Standard_MSB;
  8.           I2S_InitStructure.I2S_DataFormat = I2S_DataFormat_16b;
  9.           I2S_InitStructure.I2S_CPOL = I2S_CPOL_Low;
  10.           I2S_InitStructure.I2S_Mode = I2S_Mode_MasterTx;
  11.           I2S_InitStructure.I2S_MCLKOutput = I2S_MCLKOutput_Enable;
  12.           I2S_Init(SPI2, &I2S_InitStructure);

  13.           I2S_FullDuplexConfig(I2S2ext, &I2S_InitStructure);
  14.                 I2S_Cmd(SPI2, DISABLE);
  15.        
  16.           I2S_Cmd(I2S2ext, ENABLE);
复制代码
  1.                                        
  2.         for(i=0;i<200;i++)
  3.         {
  4.            while (SPI_I2S_GetFlagStatus(I2S2ext, SPI_FLAG_RXNE) == RESET);
  5.             soundbuf1[i] = SPI_I2S_ReceiveData(I2S2ext);
  6.                                         }
复制代码

友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
26条回答
szszjdb
2020-01-06 06:37
兄弟,多谢!
按照您的提示试过了,还是不行。现象还是I2S2ext_SD收不到任何数据,RXNE标志没有发现=1的时候。
开始时怀疑硬件连线有误,但在以下条件下检查,是可以在CODEC的MCK以及I2S2ext_SD,I2S2_SD等STM32F4 的I2S2管脚看到正常波形,
        I2S_InitStructure.I2S_Mode = I2S_Mode_MasterTx;
        I2S_FullDuplexConfig(I2S2ext, &I2S_InitStructure);
且留意到参考手册上有这么一段话,我理解是I2S2ext_SD必须在从机模式
I2Sx can operate in master mode. As a result:
• Only I2Sx can output SCK and WS in half duplex mode
• Only I2Sx can deliver SCK and WS to I2S2_ext and I2S3_ext in full duplex mode.
The extended I2Ss (I2Sx_ext) can be used only in full duplex mode. The I2Sx_ext operate
always in slave mode.
但是一旦I2S_InitStructure.I2S_Mode 设为不等于I2S_Mode_MasterTx的任何模式,如I2S_Mode_SlaveRx,I2S2ext_SD管脚测得的峰峰值马上降到1V左右,正常3.3V。不知何故。

总之,以上实验都发现I2S2ext_SD收不到任何数据,RXNE标志没有发现=1的时候。

后来怀疑I2S2ext_SD端口是否有BUG,于是从PC2,PB14,直到PI2, 3种可能的I2S2ext_SD选择都试了,现象不变。
实在是快累趴下了。服了ST了,这么重要的功能连个例子都没有。

最后将我的代码贴出,不含库文件,不知楼主能否帮我看看问题在哪里? 先谢过了!

一周热门 更多>