ADC配置如下:
GPIO_InitTypeDef GPIO_InitStruct;
ADC_InitTypeDef ADC_InitStruct;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
GPIO_StructInit(&GPIO_InitStruct);
GPIO_InitStruct.GPIO_Pin = DRIVER_KEY_GPIO_PIN;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_High;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AIN;
GPIO_Init(DRIVER_KEY_GPIO_PORT, &GPIO_InitStruct);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
ADC_StructInit(&ADC_InitStruct);
ADC_InitStruct.ADC_Resolution = ADC_Resolution_12b;
ADC_InitStruct.ADC_Prescaler = ADC_Prescaler_16;
ADC_InitStruct.ADC_Mode = ADC_Mode_Imm;
ADC_InitStruct.ADC_DataAlign = ADC_DataAlign_Right;
ADC_Init(DRIVER_KEY_ADC_PORT, &ADC_InitStruct);
ADC_ReferenceVoltageConfig(DRIVER_KEY_ADC_PORT, ADC_Select_Vref_Internal);
ADC_Cmd(DRIVER_KEY_ADC_PORT, ENABLE);
ADC_AnyChannelCmd(DRIVER_KEY_ADC_PORT, DISABLE);
ADC_ChannelCmd(DRIVER_KEY_ADC_PORT, DRIVER_KEY_ADC_CHANNEL, ENABLE);
ADC_SampleTimeConfig(DRIVER_KEY_ADC_PORT,
DRIVER_KEY_ADC_CHANNEL,
DRIVER_KEY_ADC_SAMPLE_TIME);
ADC_CalibrationConfig(DRIVER_KEY_ADC_PORT, 0x1FE); |