AD转换,EOC标志总是为0? 为何?
附代码: u16 ADSingleConvert(ADC_TypeDef* ADCx, u8 ADC_Channel) { unsigned char cADCChannelTmp; GPIO_InitTypeDef gpio_init; ADC_InitTypeDef ADCInitTmp;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1 | RCC_APB2Periph_GPIOC, ENABLE);
/* Configure GPIOC1 */ gpio_init.GPIO_Pin = DEF_BIT_01; gpio_init.GPIO_Mode = GPIO_Mode_AIN; GPIO_Init(GPIOC, &gpio_init);
cADCChannelTmp = ADC_Channel; /* ADCx Configuration (ADC1CLK = MHz) -----------------------------------*/ ADCInitTmp.ADC_Mode = ADC_Mode_Independent; ADCInitTmp.ADC_ScanConvMode = DISABLE; ADCInitTmp.ADC_ContinuousConvMode = DISABLE; ADCInitTmp.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None; ADCInitTmp.ADC_DataAlign = ADC_DataAlign_Right; ADCInitTmp.ADC_NbrOfChannel = 1;
ADC_Init(ADC1, &ADCInitTmp);
/* Enable ADC1 */ ADC_Cmd(ADC1, ENABLE);
ADC1->CR2 |= CR2_RSTCAL_Set; while(ADC_GetResetCalibrationStatus(ADC1));
ADC1->CR2 |= CR2_CAL_Set; while(ADC_GetCalibrationStatus(ADC1));
/* ADCx regular channel config */ ADC_RegularChannelConfig(ADC1, cADCChannelTmp, 1, ADC_SampleTime_1Cycles5);
ADC1->CR2 |= CR2_EXTTRIG_SWSTRT_Set;
/* wait untill convert flag EOC */ while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC)) { ; } ADC1->SR &= ~(u32)(ADC_FLAG_EOC);
return(ADC_GetConversionValue(ADC1) && 0x0FFF); } |