關(guān)于CH32V003的sleep例程中, 喚醒 IO 修改為 GPIOC4,?
模式為 GPIO_Mode_IPU (具體配置如下), 實驗發(fā)現(xiàn)該 IO 懸空時用手觸碰將喚醒?!
#include "debug.h"
void EXTI0_INT_INIT(void)
{
? ? GPIO_InitTypeDef GPIO_InitStructure = {0};
? ? EXTI_InitTypeDef EXTI_InitStructure = {0};
? ? NVIC_InitTypeDef NVIC_InitStructure = {0};
? ? RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO | RCC_APB2Periph_GPIOC, ENABLE);
? ? GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
? ? GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
? ? GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
? ? GPIO_Init(GPIOD, &GPIO_InitStructure);
? ? GPIO_EXTILineConfig(GPIO_PortSourceGPIOC, GPIO_PinSource4);
? ? EXTI_InitStructure.EXTI_Line = EXTI_Line4;
? ? EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
? ? EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
? ? EXTI_InitStructure.EXTI_LineCmd = ENABLE;
? ? EXTI_Init(&EXTI_InitStructure);
? ? NVIC_InitStructure.NVIC_IRQChannel = EXTI7_0_IRQn;
? ? NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
? ? NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
? ? NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
? ? NVIC_Init(&NVIC_InitStructure);
}
int main(void)
{
? ? NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
? ? SystemCoreClockUpdate();
? ? Delay_Init();
? ? Delay_Ms(1000);
? ? Delay_Ms(1000);
? ? USART_Printf_Init(115200);
? ? printf("SystemClk:%d\r\n", SystemCoreClock);
? ? printf( "ChipID:%08x\r\n", DBGMCU_GetCHIPID() );
? ? printf("Sleep Mode Test\r\n");
? ? EXTI0_INT_INIT();
? ? printf("\r\n ********** \r\n");
? ? __WFI();
? ? printf("\r\n ########## \r\n");
? ? while(1)
? ? {
? ? ? ? Delay_Ms(1000);
? ? ? ? printf("Run in main\r\n");
? ? ? ? printf("\r\n ********** \r\n");
? ? ? ? __WFI();
? ? ? ? printf("\r\n ########## \r\n");
? ? }
}
void EXTI7_0_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
void EXTI7_0_IRQHandler(void)
{
? ? if(EXTI_GetITStatus(EXTI_Line4)!=RESET)
? ? {
? ? ? ? printf("EXTI0 Wake_up\r\n");
? ? ? ? EXTI_ClearITPendingBit(EXTI_Line4);? ? ?/* Clear Flag */
? ? }
}