cancel
Showing results for 
Search instead for 
Did you mean: 

Using MP45DT02 on STM32F407 Discover board to save data using DMA.

cnieman12
Associate

I am wanting to sample the MP45DT02 microphone data. I am very much a beginner with this but I have cobbled together some code from some examples. Any input as to why I am not able to see any data through the DMA would be greatly appreciated.

  DMA_InitTypeDef    DMA_InitStructure;

  GPIO_InitTypeDef   GPIO_InitStructure;

  I2S_InitTypeDef I2S_InitStructure;

  SPI_InitTypeDef SPI_InitStructure;

  uint32_t       ComponentsUsed;

  // Enable clocks

  ComponentsUsed = RCC_AHB1Periph_DMA1 |

          RCC_AHB1Periph_GPIOA |

          RCC_AHB1Periph_GPIOB |

           RCC_AHB1Periph_GPIOC;

  RCC_AHB1PeriphClockCmd(ComponentsUsed, ENABLE);

  RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE);

  SPI_I2S_DeInit(SPI2);

  SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;

  SPI_InitStructure.SPI_Mode = SPI_Mode_Slave;

  SPI_InitStructure.SPI_DataSize = SPI_DataSize_16b;

  SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;

  SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;

  SPI_InitStructure.SPI_NSS = SPI_NSS_Hard;

  SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_2;

  SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;

  SPI_InitStructure.SPI_CRCPolynomial = 7;

  SPI_Init(SPI2, &SPI_InitStructure);

  I2S_InitStructure.I2S_AudioFreq = I2S_AudioFreq_48k;

  I2S_InitStructure.I2S_Standard = I2S_Standard_Phillips;

  I2S_InitStructure.I2S_DataFormat = I2S_DataFormat_16b;

  I2S_InitStructure.I2S_CPOL = I2S_CPOL_Low;

  I2S_InitStructure.I2S_Mode = I2S_Mode_MasterRx;

  I2S_InitStructure.I2S_MCLKOutput = I2S_MCLKOutput_Enable;

  I2S_Init(SPI2, &I2S_InitStructure);

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;

  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;

  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;

  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_6; // PC pins

  GPIO_Init(GPIOC, &GPIO_InitStructure);

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_10;

  GPIO_Init(GPIOB, &GPIO_InitStructure);

  GPIO_PinAFConfig(GPIOC, GPIO_PinSource3, GPIO_AF_SPI2); //I2S2_SD

  GPIO_PinAFConfig(GPIOC, GPIO_PinSource6, GPIO_AF_SPI2); // I2S2_MCK

  GPIO_PinAFConfig(GPIOB, GPIO_PinSource9, GPIO_AF_SPI2); // I2S2_WS

  GPIO_PinAFConfig(GPIOB, GPIO_PinSource10, GPIO_AF_SPI2); // I2S2_CK

  I2S_Cmd(SPI2, ENABLE);

  SPI_Cmd(SPI2, ENABLE);

  DMA_InitStructure.DMA_Channel = DMA_Channel_0;

  DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&(SPI2->DR);

  DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)i2s_raw_values_;

  DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;

  DMA_InitStructure.DMA_BufferSize = 10;

  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_Circular;

  DMA_InitStructure.DMA_Priority = DMA_Priority_High;

  DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable;

  DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_Full;

  DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;

  DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;

  DMA_Init(DMA1_Stream4, &DMA_InitStructure);

  DMA_Cmd(DMA1_Stream4, ENABLE);

  SPI_I2S_DMACmd(SPI2, SPI_I2S_DMAReq_Rx, ENABLE);

  SPI1->CR2 |= SPI_CR2_RXDMAEN;

  SPI_I2S_ReceiveData(SPI2);

0 REPLIES 0