我用模拟看门狗来检测ADC转换的电压,如果不在看门狗的区间内,则LED1亮,
如果用查询的方式来查看模拟看门狗状态,可以正常工作,改成中断方式后,ADC转换就不能进行,有高手能看一下吗?
这是部分代码。
void ADConvert_Init(void)
{
ADC_InitTypeDef ADC_InitStruct;
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1|RCC_APB2Periph_GPIOA,ENABLE);
GPIO_InitStructure.GPIO_Mode =GPIO_Mode_AIN;
GPIO_InitStructure.GPIO_Pin =GPIO_Pin_1;
GPIO_Init(GPIOA, &GPIO_InitStructure);
//ADC Init
ADC_DeInit(ADC1);
ADC_InitStruct.ADC_ContinuousConvMode =DISABLE;
ADC_InitStruct.ADC_DataAlign =ADC_DataAlign_Right;
ADC_InitStruct.ADC_ExternalTrigConv =ADC_ExternalTrigConv_None;
ADC_InitStruct.ADC_Mode =ADC_Mode_Independent;
ADC_InitStruct.ADC_NbrOfChannel=1;
ADC_InitStruct.ADC_ScanConvMode =DISABLE;
ADC_Init(ADC1, &ADC_InitStruct);
AnalogWatchDog_Set();
// ADC_AnalogWatchdogSingleChannelConfig(ADC1,ADC_Channel_1); //??ADC1_channal_1?è???????·
// ADC_AnalogWatchdogThresholdsConfig(ADC1,2482,1861);
// ADC_AnalogWatchdogCmd(ADC1,ADC_AnalogWatchdog_SingleRegEnable);
// ADC_ITConfig(ADC1, ADC_IT_AWD, ENABLE);
ADC_Cmd(ADC1,ENABLE);
ADC_ResetCalibration(ADC1);
while(ADC_GetResetCalibrationStatus(ADC1)); //??????????×??á??
ADC_StartCalibration(ADC1); //????AD??×?
while(ADC_GetCalibrationStatus(ADC1)); //??????×??á??
}
//?è???????????·
void AnalogWatchDog_Set(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
//Usart1 NVIC ????
NVIC_InitStructure.NVIC_IRQChannel = ADC1_2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=3 ;//??????????3
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3; //×???????3
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ?¨??????
NVIC_Init(&NVIC_InitStructure); //?ù?????¨????????????VIC?????÷
ADC_AnalogWatchdogSingleChannelConfig(ADC1,ADC_Channel_1); //??ADC1_channal_1?è???????·
ADC_AnalogWatchdogThresholdsConfig(ADC1,2482,1861);
ADC_AnalogWatchdogCmd(ADC1,ADC_AnalogWatchdog_SingleRegEnable);
ADC_ITConfig(ADC1, ADC_IT_AWD, ENABLE);
}
void ADC1_2_IRQHandler(void)
{
while(ADC_GetITStatus(ADC1, ADC_IT_AWD) != RESET);
ADC_ClearFlag(ADC1, ADC_FLAG_AWD);
LED1=0;
delay_ms(200);
ADC_ClearITPendingBit(ADC1, ADC_IT_AWD);
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>