单通道ADC不断采集,DMA传输,DMA缓存大小为256,利用DMA传输完成中断,采集到256后进入中断服务函数,可是我的程序进入不了中断。ADC配置:
void ADC1_Configuration(void)
{
ADC_InitTypeDef ADC_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA |RCC_APB2Periph_ADC1, ENABLE );
RCC_ADCCLKConfig(RCC_PCLK2_Div6);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
GPIO_Init(GPIOA, &GPIO_InitStructure);
ADC_DeInit(ADC1);
ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
ADC_InitStructure.ADC_ScanConvMode = DISABLE;
ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
ADC_InitStructure.ADC_NbrOfChannel = 1;
ADC_Init(ADC1, &ADC_InitStructure);
ADC_RegularChannelConfig(ADC1, ADC_Channel_11, 1, ADC_SampleTime_55Cycles5 );
ADC_DMACmd(ADC1, ENABLE);
ADC_Cmd(ADC1, ENABLE);
ADC_ResetCalibration(ADC1);
while(ADC_GetResetCalibrationStatus(ADC1));
ADC_StartCalibration(ADC1);
while(ADC_GetCalibrationStatus(ADC1));
}
DMA配置:
void DMA_Configuration(void)
{
DMA_InitTypeDef DMA_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
DMA_DeInit(DMA1_Channel1);
DMA_InitStructure.DMA_PeripheralBaseAddr = (u32)&ADC1->DR;
DMA_InitStructure.DMA_MemoryBaseAddr = (u32)&ADC_Value[256];
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
DMA_InitStructure.DMA_BufferSize = 256;
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_Channel1, &DMA_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
DMA_ITConfig(DMA1_Channel1, DMA_IT_TC , ENABLE);
DMA_Cmd(DMA1_Channel1, ENABLE);
}
中断函数:
void DMA1_Channel1_IRQHandler(void)
{
int i;
if(DMA_GetFlagStatus(DMA1_FLAG_TC1)!=RESET)
{
ADC_DMACmd(ADC1,DISABLE); //disable the adc_dma request
DMA_Cmd(DMA1_Channel1,DISABLE); //close DMA_channel1
for(i=0;i<256;i++)
{
(Yx[i]).real = (float)ADC_Value[i]*hanning256[i];
(Yx[i]).imag = 0;
}
DMA_ClearFlag(DMA1_FLAG_TC1); //clear the flag
ADC_DMACmd(ADC1,ENABLE); //enable the adc_dma request
DMA_Cmd(DMA1_Channel1,ENABLE); //enable DMA_channel1
}
}
已经验证过程序中的中断名与启动文件中的一致,还有我ADC_Value[256]中的数据也全部为0,希望能得到各位高手的指点。
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
我用的是DMA中断,ADC一直在采集,DMA_ITConfig(DMA1_Channel1, DMA_IT_TC , ENABLE); 这是DMA中断使能代码
一周热门 更多>