请教STM32 I2S从设备DMA接收输出全为0问题

2019-10-16 01:02发布

配置代码如下
GPIO_InitTypeDef  GPIO_InitStructure;
  I2S_InitTypeDef   I2S_InitStructure;
  DMA_InitTypeDef   DMA_InitStructure;
  
  RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO, ENABLE);
  
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_15 ;//I2SWS?I2SCK?I2SSD
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  GPIO_Init(GPIOB, &GPIO_InitStructure);
  
  RCC_APB1PeriphClockCmd( RCC_APB1Periph_SPI2, ENABLE);
  
  /* CODEC_I2S peripheral configuration */
  SPI_I2S_DeInit( SPI2 );
  I2S_InitStructure.I2S_AudioFreq = I2S_AudioFreq_8k;
  I2S_InitStructure.I2S_Standard = I2S_Standard_PCMShort;
  I2S_InitStructure.I2S_DataFormat = I2S_DataFormat_16b;
  I2S_InitStructure.I2S_CPOL = I2S_CPOL_Low;
  I2S_InitStructure.I2S_Mode = I2S_Mode_SlaveRx;
  I2S_InitStructure.I2S_MCLKOutput = I2S_MCLKOutput_Disable;

  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
   
  DMA_DeInit(DMA1_Channel4);
  DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)(&SPI2->DR);
  DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)DMA_Rx_Buffer;
  DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
  DMA_InitStructure.DMA_BufferSize = APP_RX_DATA_SIZE;
  DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
  DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
  DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
  DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
  DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
  DMA_InitStructure.DMA_Priority = DMA_Priority_High;
  DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
  DMA_Init(DMA1_Channel4, &DMA_InitStructure);
  DMA_Cmd(DMA1_Channel4, ENABLE);

  SPI_I2S_DMACmd(SPI2, SPI_I2S_DMAReq_Rx, ENABLE);
  I2S_Init( SPI2, &I2S_InitStructure );
  I2S_Cmd( SPI2, ENABLE );
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。