i2s半双工模式,dma读取数据,使用dma的哪个通道?
为什么我配置的是数据流3的通道0(DMA1_Stream 3_Channel 0),但是触发中断时却是DMA1_Stream 3_Channel 3触发传输完成中断,DMA1_Stream 3_Channel 0一直没有触发传输完成中断?
程序并没有配置DMA1_Stream 3_Channel 3,但是DMA1_Stream 3_Channel 3触发的时间间隔还是正确的,数据也通过DMA1_Stream 3_Channel 3传输成功了?
程序如下:
void Mic_Init(void)
{
/*定义结构体变量*/
GPIO_InitTypeDef GPIO_InitStructure;
I2S_InitTypeDef I2S_InitStructure;
DMA_InitTypeDef DMA_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
/*配置
时钟*/
RCC_I2SCLKConfig(RCC_I2S2CLKSource_PLLI2S);
RCC_PLLI2SCmd(ENABLE);
RCC_GetFlagStatus(RCC_FLAG_PLLI2SRDY);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB,ENABLE); /*使能GPIOA时钟*/
RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2,ENABLE); /*使能SPI2时钟*/
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA1,ENABLE); /*使能DMA1时钟*/
/*************************************************************************************************************/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_14;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;//普通输出模式
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;//推挽输出
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;//100MHz
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;//上拉
GPIO_Init(GPIOB, &GPIO_InitStructure);//初始化
//SCK -> PB13
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;
GPIO_Init( GPIOB , &GPIO_InitStructure );
GPIO_PinAFConfig( GPIOB , GPIO_PinSource13 , GPIO_AF_SPI2 );
//SD -> PB15
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15;
GPIO_Init( GPIOB , &GPIO_InitStructure );
GPIO_PinAFConfig( GPIOB , GPIO_PinSource15 , GPIO_AF_SPI2 );
//WS -> PB12
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
GPIO_Init( GPIOB , &GPIO_InitStructure );
GPIO_PinAFConfig( GPIOB , GPIO_PinSource12 , GPIO_AF_SPI2 );
MIC_EN = 0;
/*************************************************************************************************************/
/*复位
tiM2*/
SPI_I2S_DeInit(SPI2);
I2S_InitStructure.I2S_AudioFreq = REC_FREQ;
I2S_InitStructure.I2S_Standard = I2S_Standard_Phillips;
I2S_InitStructure.I2S_DataFormat = I2S_DataFormat_24b;
I2S_InitStructure.I2S_CPOL = I2S_CPOL_High;
I2S_InitStructure.I2S_Mode = I2S_Mode_MasterRx;
I2S_InitStructure.I2S_MCLKOutput = I2S_MCLKOutput_Disable;
I2S_Init(SPI2, &I2S_InitStructure);
SPI_I2S_DMACmd(SPI2,SPI_I2S_DMAReq_Rx,ENABLE);//SPI2 TX DMA请求使能.
I2S_Cmd(SPI2, ENABLE);
/*************************************************************************************************************/
/*复位 DMA1 数据流4*/
DMA_DeInit(DMA1_Stream3);
/*初始化 DMA1 数据流3 寄存器*/
DMA_InitStructure.DMA_Channel = DMA_Channel_0; /*DMA2 数据流0 通道0*/
DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&(SPI2->DR); /*ADC数据
存储地址*/
DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)mic_result1; /*内存地址*/
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory; /*传输方向是从外设到内存*/
DMA_InitStructure.DMA_BufferSize = REC_DATA; /*每次数据传输的数量*/
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; /*ADC数据存储地址不增加*/
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; /*内存地址增加*/
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord; /*ADC数据长度半字,两个字节*/
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord; /*内存数据长度半字,两个字节*/
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular; /*循环模式*/
DMA_InitStructure.DMA_Priority = DMA_Priority_VeryHigh; /*高优先级*/
DMA_InitStructure.DMA_F
IFOMode = DMA_FIFOMode_Disable; /*禁止FIFO*/
DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_HalfFull; /*FIFO的阈值*///?
DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single; /*单次传输*///?
DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single; /*单次传输*///?
DMA_Init(DMA1_Stream3,&DMA_InitStructure); /*初始化*/
NVIC_InitStructure.NVIC_IRQChannel = DMA1_Stream3_IRQn; /*DMA2 数据流0中断*/
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; /*抢占优先级为0*/
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; /*子优先级为0*/
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; /*中断使能*/
NVIC_Init(&NVIC_InitStructure);
/*初始化 DMA2 数据流0 的双缓存模式,DMA_Memory_0首先被传输*/
DMA_DoubleBufferModeConfig(DMA1_Stream3,(uint32_t)mic_result2,DMA_Memory_0);
/*使能 DMA2 数据流0 的双缓存模式*/
DMA_DoubleBufferModeCmd(DMA1_Stream3,ENABLE);
/*使能 DMA2 数据流0 的传输完成中断*/
DMA_ITConfig( DMA1_Stream3, DMA_IT_TC, ENABLE );
/*清楚中断标志位*/
DMA_ClearITPendingBit ( DMA1_Stream3, DMA_IT_TCIF0 );
/*开启DMA传输*/
DMA_Cmd(DMA1_Stream3,ENABLE);
}
换言之,你怎么判断的?
一周热门 更多>