void GP2Y_ADC_init()
{
GPIO_InitTypeDef GPIO_InitStructure;
ADC_InitTypeDef ADC_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOF|RCC_APB2Periph_AFIO|RCC_APB2Periph_ADC3,ENABLE);
RCC_ADCCLKConfig(RCC_PCLK2_Div6);//12M 最大14M 设置ADC时钟(ADCCLK)
ADC_DeInit(ADC3);
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_6;//ADC
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AIN; //模拟输入
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOF,&GPIO_InitStructure);
ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
ADC_InitStructure.ADC_ScanConvMode = DISABLE;
ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
ADC_InitStructure.ADC_NbrOfChannel = 4;
ADC_Init(ADC3, &ADC_InitStructure);
//设置指定ADC的规则组通道,设置它们的转化顺序和采样时间
// ADC_RegularChannelConfig(ADC1,ADC_Channel_1,1,ADC_SampleTime_239Cycles5);
//内部温度传感器是在ADC1通道16的。
ADC_RegularChannelConfig(ADC3,ADC_Channel_4,1,ADC_SampleTime_239Cycles5);
// ADC_TempSensorVrefintCmd(ENABLE);//打开内部温度传感器使能
ADC_Cmd(ADC3,ENABLE);
ADC_ResetCalibration(ADC3);//重置指定的ADC的校准寄存器
while(ADC_GetResetCalibrationStatus(ADC3));//获取ADC重置校准寄存器的状态
ADC_StartCalibration(ADC3);//开始指定ADC的校准状态
while(ADC_GetCalibrationStatus(ADC3));//获取指定ADC的校准程序
ADC_SoftwareStartConvCmd(ADC3, ENABLE);//使能或者失能指定的ADC的软件转换启动功能
GPIO_SetBits(GPIOC, GPIO_Pin_2);//置1
|