/*配置ADC1*/ void ADC1_Configuration(void) { ADC_InitTypeDef ADC_InitStructure;
ADC_DeInit(ADC1); //将外设 ADC1 的全部寄存器重设为缺省值
/* ADC1 configuration------------------------------------------------------*/ ADC_InitStructure.ADC_Mode= ADC_Mode_Independent; //ADC工作模式:ADC1和ADC2工作在独立模式 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数据右对齐 ADC_InitStructure.ADC_NbrOfChannel= M; //顺序进行规则转换的ADC通道的数目 ADC_Init(ADC1,&ADC_InitStructure); //根据ADC_InitStruct中指定的参数初始化外设ADCx的寄存器
/*ADC1 regular channel11 configuration */ //设置指定ADC的规则组通道,设置它们的转化顺序和采样时间 //ADC1,ADC通道x,规则采样顺序值为y,采样时间为239.5周期 ADC_RegularChannelConfig(ADC1,ADC_Channel_0, 1, ADC_SampleTime_239Cycles5 ); ADC_RegularChannelConfig(ADC1,ADC_Channel_1, 2, ADC_SampleTime_239Cycles5 ); ADC_RegularChannelConfig(ADC1,ADC_Channel_2, 3, ADC_SampleTime_239Cycles5 ); ADC_RegularChannelConfig(ADC1,ADC_Channel_3, 4, ADC_SampleTime_239Cycles5 ); ADC_RegularChannelConfig(ADC1,ADC_Channel_8, 5, ADC_SampleTime_239Cycles5 ); ADC_RegularChannelConfig(ADC1,ADC_Channel_9, 6, ADC_SampleTime_239Cycles5 ); ADC_RegularChannelConfig(ADC1,ADC_Channel_10, 7, ADC_SampleTime_239Cycles5 ); ADC_RegularChannelConfig(ADC1,ADC_Channel_11, 8, ADC_SampleTime_239Cycles5 ); ADC_RegularChannelConfig(ADC1,ADC_Channel_12, 9, ADC_SampleTime_239Cycles5 ); ADC_RegularChannelConfig(ADC1,ADC_Channel_13, 10, ADC_SampleTime_239Cycles5 ); ADC_RegularChannelConfig(ADC1,ADC_Channel_14, 11, ADC_SampleTime_239Cycles5 ); ADC_RegularChannelConfig(ADC1,ADC_Channel_15, 12, ADC_SampleTime_239Cycles5 );
// 开启ADC的DMA支持(要实现DMA功能,还需独立配置DMA通道等参数) ADC_DMACmd(ADC1, ENABLE);
/* Enable ADC1 */ ADC_Cmd(ADC1, ENABLE); //使能指定的ADC1 /* Enable ADC1reset calibaration register */ ADC_ResetCalibration(ADC1); //复位指定的ADC1的校准寄存器 /* Check the end of ADC1 reset calibration register */ while(ADC_GetResetCalibrationStatus(ADC1)); //获取ADC1复位校准寄存器的状态,设置状态则等待
/* Start ADC1 calibaration */ ADC_StartCalibration(ADC1); //开始指定ADC1的校准状态 /* Check the end of ADC1 calibration */ while(ADC_GetCalibrationStatus(ADC1)); //获取指定ADC1的校准程序,设置状态则等待
}
|