学习stm32f103,发现网上大多用DMA实现多通道、连续转换。现在我想用中断方式实现ADC多通道、连续转换。中断采用50us软件触发一次(50us采用TIM4定时,在TIM4的50us中断中软件触发ADC转换),下面是我的代码,请大家帮我分析是否设置正确,谢谢。
void ADC1_Configuration(void)
{
ADC_InitTypeDef ADC_InitStructure;
ADC_InitStructure.ADC_Mode = ADC_Mode_Independent; ADC_InitStructure.ADC_ScanConvMode = ENABLE; ADC_InitStructure.ADC_ContinuousConvMode = ENABLE; ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None; ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; ADC_InitStructure.ADC_NbrOfChannel = 9; ADC_Init(ADC1, &ADC_InitStructure); /* ADC1 regular channel9 configuration */ ADC_RegularChannelConfig(ADC1,ADC_Channel_0,1,ADC_SampleTime_28Cycles5);
ADC_RegularChannelConfig(ADC1,ADC_Channel_1,1,ADC_SampleTime_28Cycles5);
ADC_RegularChannelConfig(ADC1,ADC_Channel_2,1,ADC_SampleTime_28Cycles5);
ADC_RegularChannelConfig(ADC1,ADC_Channel_3,1,ADC_SampleTime_28Cycles5);
ADC_RegularChannelConfig(ADC1,ADC_Channel_4,1,ADC_SampleTime_28Cycles5);
ADC_RegularChannelConfig(ADC1,ADC_Channel_5,1,ADC_SampleTime_28Cycles5);
ADC_RegularChannelConfig(ADC1,ADC_Channel_6,1,ADC_SampleTime_28Cycles5);
ADC_RegularChannelConfig(ADC1,ADC_Channel_7,1,ADC_SampleTime_28Cycles5);
ADC_RegularChannelConfig(ADC1,ADC_Channel_8,1,ADC_SampleTime_28Cycles5);
/* Enable ADC1 EOC interrupt */
ADC_ITConfig(ADC1, ADC_IT_EOC, ENABLE);
/* Enable ADC1 */
ADC_Cmd(ADC1, ENABLE);
/* Enable ADC1 reset calibration register */
ADC_ResetCalibration(ADC1);
/* Check the end of ADC1 reset calibration register */
while(ADC_GetResetCalibrationStatus(ADC1));
/* Start ADC1 calibration */
ADC_StartCalibration(ADC1);
/* Check the end of ADC1 calibration */
while(ADC_GetCalibrationStatus(ADC1));
}
void TIM4_Configuration(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_DeInit(TIM4); TIM_TimeBaseStructure.TIM_Period = 50; TIM_TimeBaseStructure.TIM_Prescaler = (72 - 1); TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseInit(TIM4,&TIM_TimeBaseStructure);
TIM_ClearFlag(TIM4,TIM_FLAG_Update); TIM_ITConfig(TIM4,TIM_IT_Update,ENABLE); TIM_Cmd(TIM4,ENABLE);
}
void TIM4_IRQHandler(void)
{
if(TIM_GetITStatus(TIM4,TIM_IT_Update) != RESET)
{
/* Start ADC1 Software Conversion */
ADC_SoftwareStartConvCmd(ADC2, ENABLE);
/* Clear interrupt pending bit */
TIM_ClearITPendingBit(TIM4,TIM_IT_Update);
}
}