使用STM32F205的SPI2口配置为I2S,外接ADC--AK5358(44.1K采用率,24位,I2S模式),使用 I2S DMA接收,但没有进去DMA中断,代码如下,望大家看看是什么问题?
uint32 RX_DATA1[64];
uint32 RX_DATA2[64];
uint32 RX_LENG=64;
#define CODEC_STANDARD 0x04
#define I2S_STANDARD I2S_Standard_Phillips
DMA_InitTypeDef DMA_InitStructure;
#define DMA_MAX(x) (((x) <= DMA_MAX_SZE)? (x)
MA_MAX_SZE)
void I2S_ADC_Init(void)
{
I2S_InitTypeDef I2S_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
/******************************************************************************/
/* I2S clock configuration */
/******************************************************************************/
/* PLLI2S clock used as I2S clock source */
RCC->CFGR &= ~RCC_CFGR_I2SSRC;
/* Configure PLLI2S */
RCC->
LLI2SCFGR = (PLLI2S_N << 6) | (PLLI2S_R << 28);
/* Enable PLLI2S */
RCC->CR |= ((uint32_t)RCC_CR_PLLI2SON);
/* Wait till PLLI2S is ready */
while((RCC->CR & RCC_CR_PLLI2SRDY) == 0)
{
}
/* Enable the CODEC_I2S peripheral clock */
RCC_AHB1PeriphClockCmd(CODEC_I2S_GPIO_CLOCK, ENABLE);
/* CODEC_I2S pins configuration: WS, SCK and SD pins -----------------------------*/
GPIO_InitStructure.GPIO_Pin = CODEC_I2S_WS_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_WS_GPIO, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = CODEC_I2S_SCK_PIN;
GPIO_Init(CODEC_I2S_SCK_GPIO, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = CODEC_I2S_SD_PIN;
GPIO_Init(CODEC_I2S_SD_GPIO, &GPIO_InitStructure);
/* Connect pins to I2S peripheral */
GPIO_PinAFConfig(CODEC_I2S_WS_GPIO, CODEC_I2S_WS_PINSRC, CODEC_I2S_GPIO_AF);
GPIO_PinAFConfig(CODEC_I2S_SCK_GPIO, CODEC_I2S_SCK_PINSRC, CODEC_I2S_GPIO_AF);
GPIO_PinAFConfig(CODEC_I2S_SD_GPIO, CODEC_I2S_SD_PINSRC, CODEC_I2S_GPIO_AF);
RCC_APB1PeriphClockCmd(CODEC_I2S_CLK, ENABLE);
/* CODEC_I2S peripheral configuration */
SPI_I2S_DeInit(CODEC_I2S);
I2S_InitStructure.I2S_AudioFreq = I2S_AudioFreq_44k;
I2S_InitStructure.I2S_Standard = I2S_STANDARD;
I2S_InitStructure.I2S_DataFormat = I2S_DataFormat_24b;
I2S_InitStructure.I2S_CPOL = I2S_CPOL_Low;
I2S_InitStructure.I2S_Mode = I2S_Mode_SlaveRx;
I2S_InitStructure.I2S_MCLKOutput = I2S_MCLKOutput_Disable;
I2S_Init(CODEC_I2S, &I2S_InitStructure);
SPI_I2S_DMACmd(CODEC_I2S,SPI_I2S_DMAReq_Rx,ENABLE);//I2S2ext RX DMAó.
I2S_Cmd(SPI2,ENABLE); //I2S2ext I2S EN.
SPI_I2S_ITConfig(CODEC_I2S, SPI_I2S_IT_TXE, DISABLE);//±·
SPI_I2S_ITConfig(CODEC_I2S, SPI_I2S_IT_RXNE, DISABLE);//±
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA1,ENABLE);//DMA1±
DMA_Cmd(DMA1_Stream3, DISABLE);
DMA_DeInit(DMA1_Stream3);
while (DMA_GetCmdStatus(DMA1_Stream3) != DISABLE){}//DMA1_Stream3
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; //¨3 I2S2ext_RX¨
DMA_InitStructure.DMA_PeripheralBaseAddr =(u32)&SPI2->DR; //CODEC_I2S_ADDRESS;// (u32)&I2S2ext->DR;//è·
u32)&I2S2ext->DR>DR
DMA_InitStructure.DMA_Memory0BaseAddr = (u32)RX_DATA1;//DMA ÷0·
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;//è÷
DMA_InitStructure.DMA_BufferSize = RX_LENG;//
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_Normal;// ·
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_Stream3, &DMA_InitStructure);//DMA Stream
DMA_DoubleBufferModeConfig(DMA1_Stream3,(u32)RX_DATA2,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;//×1
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;//¨
NVIC_Init(&NVIC_InitStructure);//
DMA_Cmd(DMA1_Stream3,ENABLE);
}
void DMA1_Stream3_IRQHandler(void)
{
if(DMA_GetITStatus(DMA1_Stream3,DMA_IT_TCIF3)==SET) //DMA1_Stream3,ê±ê
{
DMA_ClearITPendingBit(DMA1_Stream3,DMA_IT_TCIF3); //ê
//i2s_rx_callback(); //÷,×÷í
}
NN++;
if(NN==1)
{
GPIO_SetBits(GPIOC, LED);
}
if(NN>=2)
{
NN=0;
GPIO_ResetBits(GPIOC, LED);
}
}
没有DMA接收中断中断产生,是那里配置出错了?如果设置开了SPI2接收中断,可以产生中断的。
一周热门 更多>