最近在学习stm32f103rbt6。发现网上都是用DMA实现ADC的多通道、连续转换。 我想用中断实现ADC的多通道、单次转换。在中断函数里读取每次转换的结果,但是,用我下面的代码,只能实现读出一个通道的转换结果。百思不得其解,请大家帮我分析分析。谢谢!
void ADC_init(void)
{
ADC_InitTypeDef ADC_InitStructure;
ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
ADC_InitStructure.ADC_ScanConvMode = ENABLE;
ADC_InitStructure.ADC_ContinuousConvMode = DISABLE; // 单次转换
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
ADC_InitStructure.ADC_NbrOfChannel = 2;
ADC_Init(ADC1, &ADC_InitStructure);
ADC_RegularChannelConfig(ADC1, ADC_Channel_16, 2, ADC_SampleTime_239Cycles5);
ADC_RegularChannelConfig(ADC1, ADC_Channel_17, 1, ADC_SampleTime_239Cycles5);
ADC_TempSensorVrefintCmd(ENABLE);
ADC_Cmd(ADC1, ENABLE);
ADC_ResetCalibration(ADC1);
while(ADC_GetResetCalibrationStatus(ADC1));
ADC_StartCalibration(ADC1);//开始校准
while(ADC_GetCalibrationStatus(ADC1));//等待校准完成
ADC_ITConfig(ADC1, ADC_IT_EOC, ENABLE);
}
u16 Get_ADC(void)
{
unsigned int i;
u16 temper=0,temp=0;
temp=ADC_GetConversionValue(ADC1);
temper +=temp;
Delay(0xfff);
return temper;
}
void ADC1_2_IRQHandler(void)
{
ADC_Temp=Get_ADC(); //ADC_Temp 和 Vsense 是全局变量
printf(" %d",ADC_Temp);
Vsense=(ADC_Temp*3.3)/4096;
printf("the temperature now is : %.2f\n",Vsense);
ADC_ClearITPendingBit(ADC1, ADC_IT_EOC);
} |