void I2S3_Init(u16 I2S_Standard,u16 I2S_Mode,u16 I2S_Clock_Polarity,u16 I2S_DataFormat)
{
I2S_InitTypeDef I2S_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI3, ENABLE);//ʹÄÜSPI2ʱÖÓ
RCC_APB1PeriphResetCmd(RCC_APB1Periph_SPI3,ENABLE); //¸´Î»SPI2
RCC_APB1PeriphResetCmd(RCC_APB1Periph_SPI3,DISABLE);//½áÊø¸´Î»
I2S_InitStructure.I2S_Mode=I2S_Mode;//IISģʽ
I2S_InitStructure.I2S_Standard=I2S_Standard;//IIS±ê×¼
I2S_InitStructure.I2S_DataFormat=I2S_DataFormat;//IISÊý¾Ý³¤¶È
I2S_InitStructure.I2S_MCLKOutput=I2S_MCLKOutput_Disable;//Ö÷ʱÖÓÊä³ö½ûÖ¹
I2S_InitStructure.I2S_AudioFreq=I2S_AudioFreq_Default;//IISƵÂÊÉèÖÃ
I2S_InitStructure.I2S_CPOL=I2S_Clock_Polarity;//¿ÕÏÐ״̬ʱÖÓµçƽ
I2S_Init(SPI3,&I2S_InitStructure);//³õʼ»¯IIS
SPI_I2S_DMACmd(SPI3,SPI_I2S_DMAReq_Tx,ENABLE);//SPI2 TX DMAÇëÇóʹÄÜ.
I2S_Cmd(SPI3,ENABLE);//SPI2 I2S ENʹÄÜ.
}
void I2S3ext_Init(u16 I2S_Standard,u16 I2S_Mode,u16 I2S_Clock_Polarity,u16 I2S_DataFormat)
{
I2S_InitTypeDef I2S3ext_InitStructure;
I2S3ext_InitStructure.I2S_Mode=I2S_Mode^(1<<8);//IISģʽ
I2S3ext_InitStructure.I2S_Standard=I2S_Standard;//IIS±ê×¼
I2S3ext_InitStructure.I2S_DataFormat=I2S_DataFormat;//IISÊý¾Ý³¤¶È
I2S3ext_InitStructure.I2S_MCLKOutput=I2S_MCLKOutput_Disable;//Ö÷ʱÖÓÊä³ö½ûÖ¹
I2S3ext_InitStructure.I2S_AudioFreq=I2S_AudioFreq_Default;//IISƵÂÊÉèÖÃ
I2S3ext_InitStructure.I2S_CPOL=I2S_Clock_Polarity;//¿ÕÏÐ״̬ʱÖÓµçƽ
I2S_FullDuplexConfig(I2S3ext,&I2S3ext_InitStructure);//³õʼ»¯I2S2extÅäÖÃ
SPI_I2S_DMACmd(I2S3ext,SPI_I2S_DMAReq_Rx,ENABLE);//I2S2ext RX DMAÇëÇóʹÄÜ.
I2S_Cmd(I2S3ext,ENABLE); //I2S2ext I2S ENʹÄÜ.
}
void I2S3_TX_DMA_Init(u8* buf0,u8 *buf1,u16 num)
{
NVIC_InitTypeDef NVIC_InitStructure;
DMA_InitTypeDef DMA_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA1,ENABLE);//DMA1ʱÖÓʹÄÜ
DMA_DeInit(DMA1_Stream5);
while (DMA_GetCmdStatus(DMA1_Stream5) != DISABLE){}//µÈ´ýDMA1_Stream5¿ÉÅäÖÃ
DMA_ClearITPendingBit(DMA1_Stream5,DMA_IT_FEIF5|DMA_IT_DMEIF5|DMA_IT_TEIF5|DMA_IT_HTIF5|DMA_IT_TCIF5);//Çå¿ÕDMA1_Stream5ÉÏËùÓÐÖжϱêÖ¾
/* ÅäÖÃ DMA Stream */
DMA_InitStructure.DMA_Channel = DMA_Channel_0; //ͨµÀ
DMA_InitStructure.DMA_PeripheralBaseAddr = (u32)&SPI3->DR;//ÍâÉèµØַΪ:(u32)&SPI2->DR
DMA_InitStructure.DMA_Memory0BaseAddr = (u32)buf0;//DMA ´æ´¢Æ÷0µØÖ·
DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral;//´æ´¢Æ÷µ½ÍâÉèģʽ
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_HalfWord;//ÍâÉèÊý¾Ý³¤¶È:16λ
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;//´æ´¢Æ÷Êý¾Ý³¤¶È£º16λ
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;// ʹÓÃÑ»·Ä£Ê½
DMA_InitStructure.DMA_Priority = DMA_Priority_High;//¸ßÓÅÏȼ¶
DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable; //²»Ê¹ÓÃFIFOģʽ
DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_1QuarterFull;
DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;//ÍâÉèÍ»·¢µ¥´Î´«Êä
DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;//´æ´¢Æ÷Í»·¢µ¥´Î´«Êä
DMA_Init(DMA1_Stream5, &DMA_InitStructure);//³õʼ»¯DMA Stream
DMA_DoubleBufferModeConfig(DMA1_Stream5,(u32)buf1,DMA_Memory_0);//Ë«»º³åģʽÅäÖÃ
DMA_DoubleBufferModeCmd(DMA1_Stream5,ENABLE);//Ë«»º³åģʽ¿ªÆô
DMA_ITConfig(DMA1_Stream5,DMA_IT_TC,ENABLE);//¿ªÆô´«ÊäÍê³ÉÖжÏ
NVIC_InitStructure.NVIC_IRQChannel = DMA1_Stream5_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x00;//ÇÀÕ¼ÓÅÏȼ¶0
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x00;//×ÓÓÅÏȼ¶0
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;//ʹÄÜÍⲿÖжÏͨµÀ
NVIC_Init(&NVIC_InitStructure);//ÅäÖÃ
}
void I2S3ext_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_DeInit(DMA1_Stream0);
while (DMA_GetCmdStatus(DMA1_Stream0) != DISABLE){}//µÈ´ýDMA1_Stream3¿ÉÅäÖÃ
DMA_ClearITPendingBit(DMA1_Stream0,DMA_IT_FEIF0|DMA_IT_DMEIF0|DMA_IT_TEIF0|DMA_IT_HTIF0|DMA_IT_TCIF0);//Çå¿ÕDMA1_Stream3ÉÏËùÓÐÖжϱêÖ¾
/* ÅäÖÃ DMA Stream */
DMA_InitStructure.DMA_Channel = DMA_Channel_3; //ͨµÀ3 I2S2ext_RXͨµÀ
DMA_InitStructure.DMA_PeripheralBaseAddr = (u32)&I2S3ext->DR;//ÍâÉèµØַΪ:(u32)&I2S2ext->DR>DR
DMA_InitStructure.DMA_Memory0BaseAddr = (u32)buf0;//DMA ´æ´¢Æ÷0µØÖ·
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_HalfWord;//ÍâÉèÊý¾Ý³¤¶È:16λ
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;//´æ´¢Æ÷Êý¾Ý³¤¶È£º16λ
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;// ʹÓÃÑ»·Ä£Ê½
DMA_InitStructure.DMA_Priority = DMA_Priority_Medium;//ÖеÈÓÅÏȼ¶
DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable; //²»Ê¹ÓÃFIFOģʽ
DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_1QuarterFull;
DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;//ÍâÉèÍ»·¢µ¥´Î´«Êä
DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;//´æ´¢Æ÷Í»·¢µ¥´Î´«Êä
DMA_Init(DMA1_Stream0, &DMA_InitStructure);//³õʼ»¯DMA Stream
DMA_DoubleBufferModeConfig(DMA1_Stream0,(u32)buf1,DMA_Memory_0);//Ë«»º³åģʽÅäÖÃ
DMA_DoubleBufferModeCmd(DMA1_Stream0,ENABLE);//Ë«»º³åģʽ¿ªÆô
DMA_ITConfig(DMA1_Stream0,DMA_IT_TC,ENABLE);//¿ªÆô´«ÊäÍê³ÉÖжÏ
NVIC_InitStructure.NVIC_IRQChannel = DMA1_Stream0_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority =0x00;//ÇÀÕ¼ÓÅÏȼ¶0
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x00;//×ÓÓÅÏȼ¶1
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;//ʹÄÜÍⲿÖжÏͨµÀ
NVIC_Init(&NVIC_InitStructure);//ÅäÖÃ
}
这是我配置的SPI3和DMA,大哥帮忙看一下,找了好几天原因了,不知道什么地方出错了,帮忙看一下配置的对不对 |