STM32F103RC配置I2S从模式输出+DMA不能工作,不会进入中断,哪里错了?
void I2S2_Configuration(u32 I2S_AudioFreq)
{
I2S_InitTypeDef I2S_InitStructure;
DMA_InitTypeDef DMA_InitStructure;
//GPIOB
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_12|GPIO_Pin_13;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOB, &GPIO_InitStruct);
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_15;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStruct);
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE);
//DMA1 channel 5
DMA_DeInit(DMA1_Channel5);
DMA_InitStructure.DMA_PeripheralBaseAddr = ((u32)(SPI2_BASE+0x0c)); //配置 DMA 的寄存器端为 i2s 的数据地址
DMA_InitStructure.DMA_MemoryBaseAddr = (u32)I2S2_Buffer; //配置 DMA 的内存端为我们定义的数组首地址
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST; //规定数据传输方向
DMA_InitStructure.DMA_BufferSize = I2S2_BUFFER_SIZE; //目的端的个数
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通道优先级
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; //memory- to-memory转换
DMA_Init(DMA1_Channel5, &DMA_InitStructure); //初始化DMA通道1
SPI_I2S_DMACmd(SPI2, SPI_I2S_DMAReq_Tx, ENABLE); // 允许DMA数据发送
DMA_ITConfig(DMA1_Channel5, DMA_IT_HT|DMA_IT_TC, ENABLE); //使能DMA传输过半中断和完成中断
DMA_SetCurrDataCounter(DMA1_Channel5, 0);
DMA_ClearFlag(DMA1_FLAG_TC5 | DMA1_FLAG_TE5 | DMA1_FLAG_HT5 | DMA1_FLAG_GL5);//清除DMA1 channel5标志
DMA_Cmd(DMA1_Channel5, ENABLE); //配置完成后,启动DMA通道
// I2S 2
SPI_I2S_DeInit(SPI2);
I2S_InitStructure.I2S_Mode = I2S_Mode_SlaveTx;
I2S_InitStructure.I2S_Standard = I2S_Standard_Phillips;
I2S_InitStructure.I2S_DataFormat = I2S_DataFormat_16bextended;
I2S_InitStructure.I2S_MCLKOutput = I2S_MCLKOutput_Disable;
I2S_InitStructure.I2S_AudioFreq = I2S_AudioFreq;
I2S_InitStructure.I2S_CPOL = I2S_CPOL_Low;
I2S_Init(SPI2, &I2S_InitStructure);
I2S_Cmd(SPI2, ENABLE);
}
void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0); //向量表位于FLASH
NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel5_IRQn; //更新事件
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; //抢占优先级0
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; //响应优先级
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //允许中断
NVIC_Init(&NVIC_InitStructure); //写入设置
}
|