先說實(shí)驗(yàn)結(jié)論:直接采用官方評估版與評估代碼,PA0可以順利喚醒MCU,但是自己寫的外部中斷函數(shù)無法喚醒
實(shí)驗(yàn)內(nèi)容:
先看參考手冊
再貼代碼,直接拿CH32L103EVT.ZIP壓縮包中的CH32L103EVT.ZIP\EVT\EXAM\PWR\Standby_Mode\修改
/********************************************************************* ?*?@fn??????EXTI15_10_IRQHandler ?* ?*?@brief???This?function?handles?EXTI10~15?Handler. ?* ?*?@return??none ?*/ void?EXTI15_10_IRQHandler(void)?__attribute__((interrupt("WCH-Interrupt-fast"))); void?EXTI15_10_IRQHandler(void) { ????//KEY2?pressed ????if(EXTI_GetITStatus(EXTI_Line14)!=RESET) ????{ ????????EXTI_ClearITPendingBit(EXTI_Line14);?????/*?Clear?Flag?*/ ????????printf("PB14?wakeup!\r\n"); ????????return; ????} } /********************************************************************* ?*?@fn??????main ?* ?*?@brief???Main?program. ?* ?*?@return??none ?*/ int?main(void) { ????GPIO_InitTypeDef?GPIO_InitStructure?=?{0}; ????EXTI_InitTypeDef?EXTI_InitStructure?=?{0}; ????NVIC_InitTypeDef?NVIC_InitStructure?=?{0}; ????/*?To?reduce?power?consumption,?unused?GPIOs?need?to?be?set?as?pull-down?inputs?*/ ????RCC_PB2PeriphClockCmd(RCC_PB2Periph_GPIOA|RCC_PB2Periph_GPIOB| ????????????RCC_PB2Periph_GPIOC|RCC_PB2Periph_GPIOD,?ENABLE); ????GPIO_InitStructure.GPIO_Pin?=?GPIO_Pin_All; ????GPIO_InitStructure.GPIO_Mode?=?GPIO_Mode_IPD; ????GPIO_Init(GPIOA,?&GPIO_InitStructure); ????GPIO_Init(GPIOB,?&GPIO_InitStructure); ????GPIO_Init(GPIOC,?&GPIO_InitStructure); ????GPIO_Init(GPIOD,?&GPIO_InitStructure); ????NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1); ????//PB14?is?used?as?wake?up?key ????GPIO_EXTILineConfig(GPIO_PortSourceGPIOB,?GPIO_PinSource14); ????EXTI_InitStructure.EXTI_Line?=?EXTI_Line14; ????EXTI_InitStructure.EXTI_Mode?=?EXTI_Mode_Interrupt; ????EXTI_InitStructure.EXTI_Trigger?=?EXTI_Trigger_Rising; ????EXTI_InitStructure.EXTI_LineCmd?=?ENABLE; ????EXTI_Init(&EXTI_InitStructure); ????NVIC_InitStructure.NVIC_IRQChannel?=?EXTI15_10_IRQn; ????NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority?=?1; ????NVIC_InitStructure.NVIC_IRQChannelSubPriority?=?1; ????NVIC_InitStructure.NVIC_IRQChannelCmd?=?ENABLE; ????NVIC_Init(&NVIC_InitStructure); ????SystemCoreClockUpdate(); ????Delay_Init(); ????USART_Printf_Init(115200); ????printf("SystemClk:%d\r\n",?SystemCoreClock); ????printf(?"ChipID:%08x\r\n",?DBGMCU_GetCHIPID()?); ????printf("Standby?Mode?Test\r\n"); ????RCC_PB1PeriphClockCmd(RCC_PB1Periph_PWR,?ENABLE); ????if(PWR_GetFlagStatus(PWR_FLAG_WU)?==?SET) ????{ ????????printf("\r\n?Standby?wake?up?reset?\r\n"); ????} ????else ????{ ????????printf("\r\n?Power?on?reset?\r\n"); ????????PWR_WakeUpPinCmd(ENABLE); ????????PWR_EnterSTANDBYMode(); ????} ????printf("\r\n?##########?\r\n"); ????while(1) ????{ ????????Delay_Ms(1000); ????????printf("Run?in?main\r\n"); ????} }
結(jié)果就是沒有進(jìn)入standby狀態(tài),在執(zhí)行while(1)這個循環(huán)時,把PB14拉高能觸發(fā)中斷,串口也能看到輸出
PB14?wakeup!
但是斷電重新上電后,顯示:
SystemClk:96000000
ChipID:10310710
Standby Mode Test
?Power on reset?
這時就PB14再沒法喚醒MCU了,這時將PA0拉高能喚醒。
這與手冊描述的不一致,是不是還需要哪些地方設(shè)置?