STM32F103芯片,ADC1,PC4引脚。每隔1秒钟扫描一次,由于PC4引脚还有其他用处,所以我是在扫描之前才配置引脚的。
初始化部分:
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1 | RCC_APB2Periph_AFIO , ENABLE);
RCC_ADCCLKConfig(RCC_PCLK2_Div8);
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 = 1; //
ADC_Init(ADC1, &ADC_InitStructure);
ADC_RegularChannelConfig(ADC1, ADC_Channel_14, 1, ADC_SampleTime_55Cycles5);
ADC_Cmd(ADC1, ENABLE); //
ADC_ResetCalibration(ADC1); //
while(ADC_GetResetCalibrationStatus(ADC1)); //
ADC_StartCalibration(ADC1); //
while(ADC_GetCalibrationStatus(ADC1)); //
ADC_SoftwareStartConvCmd(ADC1, DISABLE); //
下面是扫描部分:
NVIC_DisableIRQ(EXTI4_IRQn);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
GPIO_Init(GPIOC, &GPIO_InitStructure);
ADC_Cmd(ADC1, ENABLE);
ADC_SoftwareStartConvCmd(ADC1, ENABLE); //
while(ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC)==RESET);
adc=ADC_GetConversionValue(ADC1);
ADC_ClearFlag(ADC1, ADC_FLAG_EOC);
ADC_SoftwareStartConvCmd(ADC1, DISABLE); //
ADC_Cmd(ADC1, DISABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_input;
GPIO_Init(GPIOC, &GPIO_InitStructure);
NVIC_EnableIRQ(EXTI4_IRQn);
发现程序是在while(ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC)==RESET);这一行死循环,请问是哪里出了问题? |