参考下这个配置:
__RCU_AHB_CLK_ENABLE(RCU_AHB_PERI_GPIOA); //打开GPIO时钟
__RCU_APB1_CLK_ENABLE(RCU_APB1_PERI_ADADC); //打开ADC时钟
rcu_adcclk_config(adcfs); //配置adc时钟源
adc_def_init(ADC1); //去初始化ADC
gpio_mode_set(GPIOA,GPIO_PIN_2,GPIO_MODE_ANALOG); //配置输入通道GPIO
gpio_mode_set(GPIOA,GPIO_PIN_3,GPIO_MODE_ANALOG); //配置输入通道GPIO
gpio_mode_set(GPIOA,GPIO_PIN_4,GPIO_MODE_ANALOG); //配置输入通道GPIO
gpio_mode_set(GPIOA,GPIO_PIN_5,GPIO_MODE_ANALOG); //配置输入通道GPIO
adc_config_t ADC_InitStructure;
ADC_InitStructure.data_rate = ADC_DATARATE_MODE_4; //配置输出数据速率:每秒采样次数 2:10sps 3:16sps 4:20sps 5:50sps 6:60sps 7:100sps 8:200sps 9:400sps
ADC_InitStructure.gain_select = ADC_GAIN_1; //ADC增益档位选择:1倍、两倍
ADC_InitStructure.setup_time = ADC_SETUP_TIME_CYCLE_2048; //配置ADC第一次转换建立时间档位
ADC_InitStructure.average_num = ADC_AVERAGE_NUM_16; //配置ADC平均次数
ADC_InitStructure.abandont_num = ADC_ABANDONT_DATA_5; //配置ADC丢弃前x笔数据
ADC_InitStructure.convert_mode = ADC_SINGLE_CONVERT_MODE; //配置ADC转换模式
ADC_InitStructure.ovrwr_mode = ADC_DATA_OVER_WRITE; //配置ADC数据溢出时覆盖模式
ADC_InitStructure.power_mode = ADC_HIGH_POWER_MODE; //配置ADC工作模式: 高功耗或低功耗
ADC_InitStructure.rst_num = ADC_RST_CYCLE_2048; //配置每次通道切换ADC复位周期个数
adc_init(ADC1,&ADC_InitStructure);
pga_config_t PGA_InitStructure;
PGA_InitStructure.pga_gain = ADC_PGA_GAIN_1; //配置PGA档位
PGA_InitStructure.din_select = PGA_BOTH_PMOS_NMOS; //配置PGA工作状态
PGA_InitStructure.pga1_enable = DISABLE; //PGA1使能 DISABLE ENABLE
PGA_InitStructure.pga_chop = PGA_CHOP_DISABLE; //配置PGA 斩波
adc_pga_init(&PGA_InitStructure);
adc_vref_soft_start(ADC1); //VREF软启动
vref_config_t vref_InitStructure;
vref_InitStructure.buffer_enable = ENABLE; //使能vref buff
vref_InitStructure.vref_enable = ENABLE; //使能vref模块
vref_InitStructure.driver = ADC_VREF_DRV_MAX_5MA; //配置VREF驱动电流为5mA
vref_InitStructure.ref_select = ADC_REF_SELECT_INNER_2P048V; //配置参考电压
adc_vref_init(&vref_InitStructure); //配置参考电压
adc_chop_freq_set(ADC1,ADC_CHOP_DIV_256); //配置斩波
adc_digital_filter_select(ADC1,ADC_FILTER_SINC3); //配置滤波器种类
adc_trigger_config(ADC1,ADC_TRIGGER_MODE_SOFT,ADC_TRIGGER_SRC_LPTIM);//软件触发
//偏移校准配置
adc_channel_config(ADC1,ADC_INPUT_CHANNEL_12,ADC_INPUT_CHANNEL_12); //配置输入为内短模式
ADC_InitStructure.convert_mode = ADC_SINGLE_CONVERT_MODE; //单次转换模式
ADC_InitStructure.average_num = ADC_AVERAGE_NUM_16; //平均次数4
adc_init(ADC1,&ADC_InitStructure);
IADC_Init(); // ADC测试
// while(!adc_software_calibration_set(ADC1,&ADC_InitStructure,&PGA_InitStructure,&vref_InitStructure)); //开始ADC偏移校准
// //恢复测试配置
adc_channel_config(ADC1,ADC_INPUT_CHANNEL_0,ADC_INPUT_CHANNEL_1); //配置输入通道
ADC_InitStructure.average_num = ADC_AVERAGE_NUM_16; //配置平均次数
ADC_InitStructure.convert_mode = ADC_CONTINUE_CONVERT_MODE ; //连续转换模式
adc_init(ADC1,&ADC_InitStructure);
/* PGA2_bypass */
ADC1->PGA |= ADC_PGA_PGA2BYP; //PGA2 bypass
ADC1->PGA &= ~ADC_PGA_PGA2_EN; //使能PGA2
ADC1->CFG3 |= ADC_CFG3_CHOPSEL; //斩波位置选择信号0:斩波位于 PGA2和ADC中 1::斩波位于ADC中,PGA2无斩波
nvic_config_t NVIC_InitStructure;
/* Enable the ADC1 Interrupt */
NVIC_InitStructure.IRQn = IRQn_ADC1;
NVIC_InitStructure.priority = 0x1;
NVIC_InitStructure.enable_flag = ENABLE;
nvic_init(&NVIC_InitStructure);
__ADC_INTR_ENABLE(ADC1,ADC_INTR_EOCIE);
adc_conversion_start(ADC1); //开始转换