时钟已经配置好,下面是初始化和转换的代码,大侠帮忙看看
void Init_ADC(void)
{
ADC_InitTypeDef ADC_InitStructure;
/* ADC1 configuration ------------------------------------------------------*/
ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
ADC_InitStructure.ADC_ScanConvMode = ENABLE; //ENABLE
ADC_InitStructure.ADC_ContinuousConvMode = DISABLE; //ENABLE
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
ADC_InitStructure.ADC_NbrOfChannel = 4;
ADC_Init(ADC1, &ADC_InitStructure);
ADC_RegularChannelConfig(ADC1, ADC_AUDIO, ADC_BUF_AUDIO, ADC_SampleTime_71Cycles5);
ADC_RegularChannelConfig(ADC1, ADC_KEY, ADC_BUF_KEY, ADC_SampleTime_71Cycles5);
ADC_RegularChannelConfig(ADC1, ADC_STUDYKEY, ADC_BUF_STUDYKEY, ADC_SampleTime_71Cycles5);
ADC_RegularChannelConfig(ADC1, ADC_TEMPSENSOR, ADC_BUF_SENSOR, ADC_SampleTime_71Cycles5);
ADC_TempSensorVrefintCmd(ENABLE);
//ADC_DMACmd(ADC1,ENABLE);
ADC_Cmd(ADC1, ENABLE);
ADC_ResetCalibration(ADC1);
while(ADC_GetResetCalibrationStatus(ADC1));
ADC_StartCalibration(ADC1);
while(ADC_GetCalibrationStatus(ADC1));
//ADC_SoftwareStartConvCmd(ADC1, ENABLE);
}
BYTE ADCConvert(BYTE ChNO)
{
WORD AdcValue;
ADC_SoftwareStartConvCmd(ADC1, ENABLE);
while(ADC_GetFlagStatus(ADC1,ADC_FLAG_EOC));
AdcValue = ADC_GetConversionValue(ADC1);
ADC_SoftwareStartConvCmd(ADC1, DISABLE);
return (BYTE)AdcValue;
} |