ADC初始化的代码如下:- void initADC(void)
- {
-
- GPIO_InitTypeDef GPIO_InitStructure;
- ADC_InitTypeDef ADC_InitStructure;
- uint32_t adc_clk = RCC_ADCCLK_PCLK_Div4;
- log("initADC: to GPIO_Configuration\n");
-
- /* Config System clocks, GPIO ports -----------------------------------------------------*/
- RCC_ADCCLKConfig(adc_clk);//配置ADC的时钟频率
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1,ENABLE);
- RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
-
- GPIO_InitStructure.GPIO_Pin=GPIO_Pin_5;
- GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AN;
- GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;//
- GPIO_Init(GPIOA,&GPIO_InitStructure);
-
- /* Config ADC1 --------------------------------------------------------------*/
- ADC_DeInit(ADC1);
- ADC_InitStructure.ADC_Resolution = ADC_Resolution_8b;//ADC_Resolution_12b
- ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;//不开启连续转换模式
- ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None; //不使用外部触发转换
- ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; //采集数据右对齐
- ADC_InitStructure.ADC_ScanDirection = ADC_ScanDirection_Upward; //扫描方向
- ADC_Init(ADC1, &ADC_InitStructure);
-
- ADC_TempSensorCmd(ENABLE);//使能内部温度传感器
- ADC_VrefintCmd(ENABLE); //使能内部参考电压
- //按 频率=8/1/4=2M 来计算,t=(71.5+12.5)/2M=42us
- // ADC_ChannelConfig(ADC1, ADC_Channel_16, ADC_SampleTime_71_5Cycles);//内部温度传感器
- ADC_ChannelConfig(ADC1, ADC_Channel_17, ADC_SampleTime_71_5Cycles);//内部参考电压
- // ADC_ChannelConfig(ADC1, ADC_Channel_5, ADC_SampleTime_71_5Cycles);//配置ADC1通道5的采样周期 PA5
-
- ADC_GetCalibrationFactor(ADC1);//Active the Calibration operation 返回校准因子 //The Calibration can be initiated only when ADC is still in the reset configuration (ADEN must be equal to 0).
-
- ADC_Cmd(ADC1,ENABLE);//ADEN set to 1
-
- while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_ADEN));
- }
|