我使用的芯片如题所示,想实现用I2S的DMA中断方式发送实时更新的数据。现在只要使能I2S时钟(不配置I2S的寄存器),再配置并使能对应I2S的DMA通道,就会触发对应的DMA中断(数据没有更新)。下面是部分源代码,请各位帮忙看下,谢谢!
使用的是I2S2通道
#define AIC23B_I2S2_SD GPIO_Pin_15
#define AIC23B_I2S2_WS GPIO_Pin_12
#define AIC23B_I2S2_CK GPIO_Pin_13
#define AIC23B_I2S2_MCK GPIO_Pin_6
#define AIC23B_BUFFER_SIZE 320*2
unsigned int testAIC23B_Buffer_IN[AIC23B_BUFFER_SIZE]; /* 用于存储接收到的声波数据 */
配置函数:
GPIO_InitTypeDef GPIO_InitStructure;
I2S_InitTypeDef I2S_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
DMA_InitTypeDef DMA_InitStructure;
if (SelectI2SChannel == I2SChannel2)
{
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC | RCC_APB2Periph_AFIO , ENABLE);
GPIO_StructInit(&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = AIC23B_I2S2_WS | AIC23B_I2S2_CK | AIC23B_I2S2_SD ;//I2SWS、I2SCK、I2SSD
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOB, &GPIO_InitStructure);
/* CODEC_I2S pins configuration: MCK pin */
GPIO_InitStructure.GPIO_Pin = AIC23B_I2S2_MCK;
GPIO_Init(GPIOC, &GPIO_InitStructure);
/* CODEC_I2S peripheral configuration */
RCC_APB1PeriphClockCmd( RCC_APB1Periph_SPI2, ENABLE);
I2S_Cmd( SPI2, DISABLE );
SPI_I2S_DeInit(SPI2);
I2S_StructInit(&I2S_InitStructure);
I2S_InitStructure.I2S_AudioFreq = I2S_AudioFreq_16k;
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_MasterTx;
I2S_InitStructure.I2S_MCLKOutput = I2S_MCLKOutput_Enable;
/* Initialize the I2S peripheral with the structure above */
I2S_Init(SPI2, &I2S_InitStructure);
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
DMA_DeInit(DMA1_Channel5);
// DMA_StructInit(&DMA_InitStructure);
DMA_InitStructure.DMA_PeripheralBaseAddr = 0x4000380C;//(uint32_t)(SPI2->DR);
DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)&AIC23B_Buffer_IN;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;
DMA_InitStructure.DMA_BufferSize = AIC23B_BUFFER_SIZE;
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_M2M = DMA_M2M_Disable;
DMA_Init(DMA1_Channel5, &DMA_InitStructure);
DMA_Cmd(DMA1_Channel5, ENABLE);
/* Enable the I2S DMA request */
SPI_I2S_DMACmd(SPI2, SPI_I2S_DMAReq_Tx, ENABLE);
/* Enable the selected DMA interrupts (selected in "stm32_eval_audio_codec.h" defines) */
DMA_ITConfig(DMA1_Channel5, DMA_IT_HT, ENABLE);
DMA_ITConfig(DMA1_Channel5, DMA_IT_TC, ENABLE);
// NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0000);
// NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0); /* 可以设置的先占优先级和从优先级 */
NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel5_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 4;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
I2S_Cmd( SPI2, ENABLE );
|