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.                                         }
复制代码

友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
25条回答
szszjdb
1楼-- · 2020-01-06 15:27
dreamc 发表于 2014-9-26 22:12
嗯 我明早帮你看下。

麻烦您了,多谢!
dreamc
2楼-- · 2020-01-06 16:03
szszjdb 发表于 2014-9-27 00:39
麻烦您了,多谢!

QQ联系吧
szszjdb
3楼-- · 2020-01-06 20:36
dreamc 发表于 2014-9-27 14:11
QQ联系吧

我的qq: 302861256 ,多谢!
szszjdb
4楼-- · 2020-01-07 00:23
 精彩回答 2  元偷偷看……
freching
5楼-- · 2020-01-07 00:32
好好好好好
szszjdb
6楼-- · 2020-01-07 04:54
dreamc 发表于 2014-9-27 14:11
QQ联系吧

多谢DREAMC兄弟帮忙查。原来是PI0/1不能用于全双工。代码没有问题。再次感谢

一周热门 更多>