I2S 时钟管脚配置 GPIO_InitTypeDef GPIO_InitStructure; I2S_InitTypeDef I2S_InitStructure; // NVIC_InitTypeDef NVIC_InitStructure; RCC_I2SCLKConfig (RCC_I2S2CLKSource_PLLI2S); /* Enable the CODEC_I2S peripheral clock */ RCC_APB1PeriphClockCmd(CODEC_I2S_CLK, ENABLE); //ʹÄÜI2SµÄʱÖÓ!! RCC_AHB1PeriphClockCmd(CODEC_I2S_GPIO_CLOCK, ENABLE); /* CODEC_I2S_2 pins configuration: WS, SCK and SD pins -----------------------------*/ GPIO_InitStructure.GPIO_Pin = CODEC_I2S_2_WS_PIN | CODEC_I2S_2_SCK_PIN | CODEC_I2S_2_SD_PIN | CODEC_I2S_2_ext_PIN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(CODEC_I2S_2_GPIO, &GPIO_InitStructure); /* Connect pins to I2S peripheral */ GPIO_PinAFConfig(CODEC_I2S_2_GPIO, CODEC_I2S_2_WS_PINSRC, CODEC_I2S_2_GPIO_AF); GPIO_PinAFConfig(CODEC_I2S_2_GPIO, CODEC_I2S_2_SCK_PINSRC, CODEC_I2S_2_GPIO_AF); GPIO_PinAFConfig(CODEC_I2S_2_GPIO, CODEC_I2S_2_SD_PINSRC, CODEC_I2S_2_GPIO_AF); GPIO_PinAFConfig(CODEC_I2S_2_GPIO, CODEC_I2S_2_ext_PINSRC, CODEC_I2S_2_GPIO_AF); //Ö÷ʱÖÓ! /* CODEC_I2S pins configuration: MCK pin */ GPIO_InitStructure.GPIO_Pin = CODEC_I2S_2_MCK_PIN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_Init(CODEC_I2S_2_MCK_GPIO, &GPIO_InitStructure); GPIO_PinAFConfig(CODEC_I2S_2_MCK_GPIO, CODEC_I2S_2_MCK_PINSRC, CODEC_I2S_2_GPIO_AF); DMA配置 void I2S2ext_RX_DMA_Init(u8* buf0,u8 *buf1,u16 num) { NVIC_InitTypeDef NVIC_InitStructure; DMA_InitTypeDef DMA_InitStructure; RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA1,ENABLE);//DMA1ʱÖÓʹÄÜ //DMA_Cmd(DMA1_Stream3, DISABLE); DMA_DeInit(DMA1_Stream3); while (DMA_GetCmdStatus(DMA1_Stream3) != DISABLE){}//µÈ´ýDMA1_Stream3¿ÉÅäÖà SPI_I2S_DMACmd(I2S2ext, SPI_I2S_DMAReq_Rx, ENABLE); DMA_ClearITPendingBit(DMA1_Stream3,DMA_IT_FEIF3|DMA_IT_DMEIF3|DMA_IT_TEIF3|DMA_IT_HTIF3|DMA_IT_TCIF3);//Çå¿ÕDMA1_Stream3ÉÏËùÓÐÖжϱêÖ¾ /* ÅäÖà DMA Stream */ DMA_InitStructure.DMA_Channel = DMA_Channel_3; DMA_InitStructure.DMA_PeripheralBaseAddr = (u32)&I2S2ext->DR; DMA_InitStructure.DMA_Memory0BaseAddr = (u32)buf0; DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory; DMA_InitStructure.DMA_BufferSize = num;//Êý¾Ý´«ÊäÁ¿ DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word; DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Word; DMA_InitStructure.DMA_Mode = DMA_Mode_Circular; DMA_InitStructure.DMA_Priority = DMA_Priority_Medium; DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable; DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_1QuarterFull; DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single; DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single; DMA_Init(DMA1_Stream3, &DMA_InitStructure); DMA_DoubleBufferModeConfig(DMA1_Stream3,(u32)buf1,DMA_Memory_0); DMA_DoubleBufferModeCmd(DMA1_Stream3,ENABLE); DMA_ITConfig(DMA1_Stream3,DMA_IT_TC,ENABLE); NVIC_InitStructure.NVIC_IRQChannel = DMA1_Stream3_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority =0x00; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x01; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure);//ÅäÖà } 中断服务函数 void DMA1_Stream3_IRQHandler(void) { int i=0; if(DMA_GetITStatus(DMA1_Stream3,DMA_IT_TCIF3)==SET) //DMA1_Stream3,´«ÊäÍê³É±êÖ¾ { DMA_ClearITPendingBit(DMA1_Stream3,DMA_IT_TCIF3); //Çå³ý´«ÊäÍê³ÉÖÐ¶Ï for(i=0;i<=1024;i++) { printf("PI %d \r\n",*(p1+i));//¸üÐÂÏÔʾÄÚÈÝ } //i2s_rx_callback(); //Ö´Ðлص÷º¯Êý,¶ÁÈ¡Êý¾ÝµÈ²Ù×÷ÔÚÕâÀïÃæ´¦Àí } } void I2S_Rec_Start(void) { DMA_Cmd(DMA1_Stream3,ENABLE);//¿ªÆôDMA TX´«Êä,¿ªÊ¼Â¼Òô } 主程序 my_I2S2ext_Init(I2S_Standard_Phillips,I2S_Mode_SlaveRx,I2S_CPOL_Low,I2S_DataFormat_32b); I2S2ext_RX_DMA_Init(p1,p2,(2*1024)); I2S_Rec_Start(); 程序是从原子的历程移植的 为何DMA的中断不能进不去,调了一上午,请各位大神帮忙看一下,不胜感激 |
è¿æ¯DMAå¯åå¨çé ç½®