需求是这样的:adc0~3通道由TIM1_TRGO触发 注入采样,adc4通道由SWSTART触发 规则采样,注入采样4路AD完成后进入ADC中断,规则采样在需要的时候开启并读取。 void adc_init(void) { ADC_InitTypeDef ADC_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1,ENABLE); RCC_ADCCLKConfig(RCC_PCLK2_Div6);//60M/6 = 10M //------------------------------------- ADC_InitStructure.ADC_Mode = ADC_Mode_Independent; ADC_InitStructure.ADC_ScanConvMode = ENABLE; ADC_InitStructure.ADC_ContinuousConvMode = DISABLE; //非连续转换 ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;//SWSTART ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; ADC_InitStructure.ADC_NbrOfChannel = 1; ADC_Init(ADC1, &ADC_InitStructure); ADC_RegularChannelConfig(ADC1,ADC_Channel_4,1,ADC_SampleTime_7Cycles5);//通道一转换结果 //------------------------------------- /* Set injected sequencer length */ ADC_InjectedSequencerLengthConfig(ADC1, 4); /* ADC1 injected channel Configuration */ ADC_InjectedChannelConfig(ADC1, ADC_Channel_0, 1, ADC_SampleTime_7Cycles5); ADC_InjectedChannelConfig(ADC1, ADC_Channel_1, 2, ADC_SampleTime_7Cycles5); ADC_InjectedChannelConfig(ADC1, ADC_Channel_2, 3, ADC_SampleTime_7Cycles5); ADC_InjectedChannelConfig(ADC1, ADC_Channel_3, 4, ADC_SampleTime_7Cycles5); /* ADC1 injected external trigger configuration */ ADC_ExternalTrigInjectedConvConfig(ADC1, ADC_ExternalTrigInjecConv_T1_TRGO); /* DISable automatic injected conversion start after regular one */ ADC_AutoInjectedConvCmd(ADC1, DISABLE); /* Enable ADC1 external trigger */ ADC_ExternalTrigConvCmd(ADC1, ENABLE); ADC_ExternalTrigInjectedConvCmd(ADC1, ENABLE); ADC1->CR1 |= 0x80; //Interrupt enable for injected channels //------------------------------------- ADC_Cmd(ADC1, ENABLE); ADC_ResetCalibration(ADC1); while(ADC_GetResetCalibrationStatus(ADC1)); ADC_StartCalibration(ADC1); while(ADC_GetCalibrationStatus(ADC1)); } |
void ADC_SoftwareStartInjectedConvCmd(ADC_TypeDef* ADCx, FunctionalState NewState)
好的,感谢