void adcinit(void) { GPIO_InitTypeDef GPIO_InitStruct; ADC_InitTypeDef ADC_InitStruct; RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1,ENABLE); RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA,ENABLE); GPIO_InitStruct.GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_4 | GPIO_Pin_5; GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AN; GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOA,&GPIO_InitStruct); ADC_InitStruct.ADC_Resolution = ADC_Resolution_12b; ADC_InitStruct.ADC_ContinuousConvMode = DISABLE; ADC_InitStruct.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None; ADC_InitStruct.ADC_DataAlign = ADC_DataAlign_Right; ADC_InitStruct.ADC_ScanDirection = ADC_ScanDirection_Upward; ADC_Init(ADC1,&ADC_InitStruct); ADC_ChannelConfig(ADC1,ADC_Channel_0,ADC_SampleTime_55_5Cycles); ADC_ChannelConfig(ADC1,ADC_Channel_1,ADC_SampleTime_55_5Cycles); ADC_ChannelConfig(ADC1,ADC_Channel_2,ADC_SampleTime_55_5Cycles); ADC_GetCalibrationFactor(ADC1); ADC_Cmd(ADC1,ENABLE); } /************************************************************** * Function Name : getadcvalue * Param : void * Return Param : void * Description : 获取adc转换结果 ***************************************************************/ void getadcvalue(void) { UINT32 idx; while(ADC_GetFlagStatus(ADC1,ADC_FLAG_ADRDY) == DISABLE); ADC_StartOfConversion(ADC1); for(idx = 0;idx < 3;idx++) { // while(ADC_GetFlagStatus(ADC1,ADC_FLAG_EOC) == DISABLE); ADC1ConvValue[idx] = ADC_GetConversionValue(ADC1); } if(ADC_GetFlagStatus(ADC1,ADC_FLAG_EOSEQ) == ENABLE) { ADC_ClearFlag(ADC1,ADC_FLAG_EOSEQ); } } 用上面的代码可以实现序列通道单次转换吗? 目的:调用一次getadcvalue() 就采集一次数据 求大神指点,while(EOC)不注释掉的话,好像只能调用一次,手册上写,EOC不是读取数据后才会清零吗? |