ADC_InitTypeDef ADC_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC2, ENABLE);
RCC_ADCCLKConfig(RCC_PCLK2_Div6);
/* ADC1 寄存器配置 */
ADC_InitStructure.ADC_Mode = ADC_Mode_RegSimult; //同步规则模式
ADC_InitStructure.ADC_ScanConvMode = ENABLE; //开启扫描模式
ADC_InitStructure.ADC_ContinuousConvMode = DISABLE; //关闭连续转换模式
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None; //禁止外部触发ADC转换
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; //对齐方式,ADC为12位,右对齐方式
ADC_InitStructure.ADC_NbrOfChannel = DMA1_BufferSize; //ADC1开启通道数
ADC_Init(ADC1, &ADC_InitStructure);
/* ADC1 regular channels configuration */
ADC_RegularChannelConfig(ADC1, ADC_Channel_16, 1, ADC_SampleTime_28Cycles5);//CPU_Temperature CPU内部温度采样(说明:ADC1_16通道是温度传感器)
ADC_RegularChannelConfig(ADC1, ADC_Channel_11, 2, ADC_SampleTime_28Cycles5); //BAT电压
ADC_RegularChannelConfig(ADC1, ADC_Channel_1, 3, ADC_SampleTime_28Cycles5); //GPAI1 电压
ADC_RegularChannelConfig(ADC1, ADC_Channel_2, 4, ADC_SampleTime_28Cycles5); //GPAI2 电压
ADC_RegularChannelConfig(ADC1, ADC_Channel_3, 5, ADC_SampleTime_28Cycles5); //GPAI3 电压
ADC_RegularChannelConfig(ADC1, ADC_Channel_4, 6, ADC_SampleTime_28Cycles5); //GPAI4 电压
ADC_RegularChannelConfig(ADC1, ADC_Channel_5, 7, ADC_SampleTime_28Cycles5); //GPAI5 电压
/* Enable ADC1 DMA */
ADC_DMACmd(ADC1, ENABLE);
/* ADC2 configuration */
ADC_InitStructure.ADC_Mode = ADC_Mode_RegSimult; //同步规则模式
ADC_InitStructure.ADC_ScanConvMode = ENABLE; //开启扫描模式
ADC_InitStructure.ADC_ContinuousConvMode = DISABLE; //关闭连续转换模式
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None; //禁止外部触发ADC转换
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; //对齐方式,ADC为12位,右对齐方式
ADC_InitStructure.ADC_NbrOfChannel = DMA1_BufferSize; //ADC2开启通道个数
ADC_Init(ADC2, &ADC_InitStructure);
/* ADC2 regular channels configuration */
ADC_RegularChannelConfig(ADC2, ADC_Channel_10, 1, ADC_SampleTime_28Cycles5);//
ADC_RegularChannelConfig(ADC2, ADC_Channel_6, 2, ADC_SampleTime_28Cycles5); //
ADC_RegularChannelConfig(ADC2, ADC_Channel_7, 3, ADC_SampleTime_28Cycles5); //GPAI7 电压
ADC_RegularChannelConfig(ADC2, ADC_Channel_14, 4, ADC_SampleTime_28Cycles5); //GPAI8 电压
ADC_RegularChannelConfig(ADC2, ADC_Channel_15, 5, ADC_SampleTime_28Cycles5); //TEMP1 电压
ADC_RegularChannelConfig(ADC2, ADC_Channel_8, 6, ADC_SampleTime_28Cycles5); //TEMP2 电压
ADC_RegularChannelConfig(ADC2, ADC_Channel_1, 7, ADC_SampleTime_28Cycles5); //GPAI1 电压
/* Enable ADC2 external trigger conversion */
ADC_ExternalTrigConvCmd(ADC2, ENABLE); //规则组队,同步模式ADC2是由ADC1触发的
/* Enable ADC1 DMA */
ADC_DMACmd(ADC1, ENABLE);
ADC_TempSensorVrefintCmd(ENABLE); //使能温度传感器和Vrefint
/* 开启ADC,并校准 */
ADC_Cmd(ADC1, ENABLE); //使能ADC1
ADC_ResetCalibration(ADC1); //复位ADC1校准寄存器
while(ADC_GetResetCalibrationStatus(ADC1)); //等待ADC1校准寄存器复位完成
ADC_StartCalibration(ADC1); //开始ADC1校准
while(ADC_GetCalibrationStatus(ADC1)); //等待ADC1校准完成
ADC_Cmd(ADC2, ENABLE); //使能ADC2
ADC_ResetCalibration(ADC2); //复位ADC2校准寄存器
while(ADC_GetResetCalibrationStatus(ADC2)); //等待ADC2校准寄存器复位完成
ADC_StartCalibration(ADC2); //开始ADC2校准
while(ADC_GetCalibrationStatus(ADC2)); //等待ADC2校准完成