初级会员

- 积分
- 155
- 金钱
- 155
- 注册时间
- 2020-5-7
- 在线时间
- 92 小时
|
5金钱
本帖最后由 taotaotao 于 2020-8-1 16:09 编辑
STM32F4 ADC设置扫描模式读取多个通道数据,怎么进入不了ADC中断,调试原子哥的例程的时候发现单步运行的话,程序会卡死在while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC ));全速运行好好的,难道ADC的EOC位另有玄机
void Adc_Init(void)
{
GPIO_InitTypeDef GPIO_Structure;
ADC_CommonInitTypeDef ADC_CommonStructure;
ADC_InitTypeDef ADC_InitStruture;
NVIC_InitTypeDef NVIC_Structure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC,ENABLE);
//采取PA4和PA6的电压
GPIO_Structure.GPIO_Mode=GPIO_Mode_AN;
GPIO_Structure.GPIO_OType=GPIO_OType_PP;
GPIO_Structure.GPIO_Pin=GPIO_Pin_6|GPIO_Pin_4;
GPIO_Structure.GPIO_PuPd=GPIO_PuPd_NOPULL;
GPIO_Init(GPIOA,&GPIO_Structure);
ADC_DeInit();
ADC_CommonStructure.ADC_DMAAccessMode=ADC_Mode_Independent;
ADC_CommonStructure.ADC_Mode=ADC_DMAAccessMode_Disabled;
ADC_CommonStructure.ADC_Prescaler=ADC_Prescaler_Div4;
ADC_CommonStructure.ADC_TwoSamplingDelay=ADC_TwoSamplingDelay_5Cycles;
ADC_CommonInit(&ADC_CommonStructure);
ADC_InitStruture.ADC_ContinuousConvMode=ENABLE;
ADC_InitStruture.ADC_DataAlign=ADC_DataAlign_Right;
//ADC_InitStruture.ADC_ExternalTrigConv=
ADC_InitStruture.ADC_ExternalTrigConvEdge=ADC_ExternalTrigConvEdge_None;
ADC_InitStruture.ADC_NbrOfConversion=2;
ADC_InitStruture.ADC_Resolution=ADC_Resolution_12b;
ADC_InitStruture.ADC_ScanConvMode=ENABLE;
ADC_Init(ADC1,&ADC_InitStruture);
ADC_Cmd(ADC1,ENABLE);
NVIC_Structure.NVIC_IRQChannel=ADC_IRQn;
NVIC_Structure.NVIC_IRQChannelCmd=ENABLE;
NVIC_Structure.NVIC_IRQChannelPreemptionPriority=3;
NVIC_Structure.NVIC_IRQChannelSubPriority=0;
NVIC_Init(&NVIC_Structure);
ADC_ITConfig(ADC1,ADC_IT_EOC,ENABLE);
ADC_SoftwareStartConv(ADC1);
ADC_RegularChannelConfig(ADC1,ADC_Channel_4,1,ADC_SampleTime_480Cycles);
ADC_RegularChannelConfig(ADC1,ADC_Channel_6,2,ADC_SampleTime_480Cycles);
}
void ADC_IRQHandler()
{
ADC_ClearITPendingBit(ADC1,ADC_IT_EOC);
if(ADC_GetITStatus(ADC1,ADC_IT_EOC))
{
channel++;
adcx=ADC_GetConversionValue(ADC1);
LED1=!LED1;
}
}
|
最佳答案
查看完整内容[请看2#楼]
【探索者_ADC多通道(有使用DMA及不使用DMA的两个版本) 双重ADC+DMA规则同步 三重ADC+DMA交替采集同一通道】http://www.openedv.com/forum.php?mod=viewthread&tid=290039
|