本帖最后由 liucan123456789 于 2023-11-2 16:02 编辑
我的想法是,按下按键 通过AWD唤醒,我按照例程配置不知道 为什么没有唤醒
/*IO初始化*/
void ADC_EXTI_GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHBPeriphClockCmd( RCC_AHBPeriph_GPIOC, ENABLE );
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC ,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG ,ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 ;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
GPIO_Init(GPIOC, &GPIO_InitStructure);
GPIO_PinAFConfig(GPIOC,GPIO_PinSource4,GPIO_AF_7);
//PC3用于触发
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3 ;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
GPIO_Init(GPIOC, &GPIO_InitStructure);
GPIO_PinAFConfig(GPIOC,GPIO_PinSource3,GPIO_AF_7);
}
/*ADC配置*/
void EXTI_ADC_Configuration(void)
{
ADC_InitTypeDef ADC_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC ,ENABLE);
ADC_DeInit(ADC1);
ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;
ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_Falling;
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_IO_TRGO; //ADC外部IO触发
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
ADC_InitStructure.ADC_ScanDirection = ADC_ScanDirection_Upward;
ADC_Init(ADC1,&ADC_InitStructure);
/* ADC1 regular channels configuration */
ADC_ChannelConfig(ADC1, ADC_Channel_2 , ADC_SampleTime_239_5Cycles);
ADC_AnalogWatchdogThresholdsConfig(ADC1,3300, 3200);//(ADC1, 3102, 1861);//输入ADCwatchdog高低阀值
ADC_AnalogWatchdogSingleChannelCmd(ADC1, ENABLE);//开启ADCwatchdog
ADC_AnalogWatchdogSingleChannelConfig(ADC1, ADC_AnalogWatchdog_Channel_2);//选择ADCwatchdog_Channel2
ADC_AWDWakeup_Cmd(ADC1,ENABLE);//使能模拟看门狗唤醒功能
ADC_AnalogWatchdogCmd(ADC1,ENABLE);//打开模拟看门狗
ADC_Cmd(ADC1, ENABLE);
ADC_ITConfig(ADC1,ADC_IT_AWD,ENABLE);
while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_ADRDY));
ADC_StartOfConversion(ADC1);
NVIC_SetPriority(ADC1_IRQn,9);
NVIC_EnableIRQ(ADC1_IRQn);
}
void Beep_ADC_Configuration(void)
{
RCC_APB1PeriphClockCmd(RCC_APB1Periph_BEEPER, ENABLE );
//RCC_AHBPeriphClockCmd( RCC_AHBPeriph_GPIOA, ENABLE);
RCC_LSICmd(ENABLE);
while(!(RCC->CSR & RCC_CSR_LSIRDY));
//GPIO_InitTypeDef GPIO_InitStructure;
BEEP_InitTypeDef BEEP_InitStructure;
// GPIO_PinAFConfig(GPIOA,GPIO_PinSource2,GPIO_AF_6);
// GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
// GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
// GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
// GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
// GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
// GPIO_Init( GPIOA, &GPIO_InitStructure );
BEEP_InitStructure.BEEP_Prescaler = BEEP_Prescaler_128;
BEEP_InitStructure.BEEP_Clock = BEEP_CLOCK_LSI;
BEEP_InitStructure.BEEP_TRGOCmd = ENABLE;
BEEP_Init(&BEEP_InitStructure);
BEEP_Cmd(ENABLE);
}
void ADC1_COMP_IRQHandler(void)
{
if(ADC_GetITStatus(ADC1, ADC_IT_AWD) != RESET)
{
/* Clear ADC1 AWD pending interrupt bit */
ADC_ClearITPendingBit(ADC1, ADC_IT_AWD);
ADC_AWDWakeup_Cmd(ADC1,DISABLE);//关闭模拟看门狗唤醒功能
ADC_AnalogWatchdogCmd(ADC1,DISABLE);//关闭模拟看门狗
ADC_Cmd(ADC1, DISABLE);
}
}
ADC_EXTI_GPIO_Configuration();
EXTI_ADC_Configuration();
Beep_ADC_Configuration();
while(ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == RESET);
ADCConvertedValue=ADC_GetConversionValue(ADC1);
EXTI->EMR |= 0x00000100;
__nop();
__nop();
PWR_EnterStopMode(PWR_Regulator_LowPower,PWR_Entry_WFE);
//PWR_EnterDeepSleepMode(PWR_Entry_WFI);
__nop();
__nop();
SystemInit ();
|