【上海航芯 ACM32F070开发板+触控功能评估板】—— EXTI例程
[复制链接]
1.3. EXTI例程
EXIT例程通过设置EXTI(外部中断/事件控制器),然后进入STOP模式,即执行WFI/WFE
- Notes:
-
-
在APP_EXTI_Test代码的前面有个System_Delay_MS(3000); 是由于进入Stop或者Sleep模式后,调试功能失去响应,无法下载/调试,比较方便的就是按下Reset键,当程序重启后,在执行这个System_Delay_MS(3000);的语句时,可以调试/下载。
-
当调试中进入Stop模式后,有时候会由于调试器试图重置处理器而发生PB1无法唤醒处理器的情况。STOP模式不适合调试。
1.3.1. TEST_EXIT_GPIO
设置PB1位输入、上拉、功能0,然后配置EXTI为LINE_1,PB1,中断模式、下降沿,最后进入Stop模式。通过WFI灯带。 .. code-block:: c++
switch(fe_Mode) {
- case TEST_EXIT_GPIO:
-
/* Initialization GPIO */ GPIO_PB1_Handle.Pin = GPIO_PIN_1; GPIO_PB1_Handle.Mode = GPIO_MODE_INPUT; GPIO_PB1_Handle.Pull = GPIO_PULLUP; GPIO_PB1_Handle.Alternate = GPIO_FUNCTION_0;
HAL_GPIO_Init(GPIOB, &GPIO_PB1_Handle);
/* Config EXTI */ EXTI_Line_Handle.u32_Line = EXTI_LINE_1; EXTI_Line_Handle.u32_Mode = EXTI_MODE_INTERRUPT; EXTI_Line_Handle.u32_Trigger = EXTI_TRIGGER_FALLING; EXTI_Line_Handle.u32_GPIOSel = EXTI_GPIOB;
HAL_EXTI_SetConfigLine(&EXTI_Line_Handle);
while (1) {
printfS(“MCU Enter Lowpower, Let PB1 Fall Down Wakeup MCU!n”); System_Enter_Stop_Mode(MODE_WFI);
printfS(“MCU is Runing rn”); System_Delay_MS(200); printfS(“MCU is Runing rn”); System_Delay_MS(200);
}
事实上,以上代码存在一个小BUG,代码 System_Enter_Stop_Mode(MODE_WFI); 中, MODE_WFI的值是0x01,而进入System_Enter_Stop_Mode函数,发现其期望的参数值为STOPENTRY_WFI(0x00)或者STOPENTRY_WFE(0x01),所以正确的代码应该是System_Enter_Stop_Mode(STOPENTRY_WFI).
运行效果如图:
1.3.2. TEST_EXTI_RTC
设置RTC为2021-03-20,时间为12:30:00,然后通过 __HAL_RTC_ENABLE_MIN_IT 使能RTC的分钟定时中断,再设置EXTI里面对应的RTC的外部中断唤醒。
case TEST_EXTI_RTC:
/********************************************/
/**************** RTC Config ****************/
/********************************************/
RTC_Handle.u32_ClockSource = RTC_CLOCK_XTL;
RTC_Handle.u32_Compensation = COMPENSATION_INCREASE; // ¿ªʼʱ֓²¹³¥£¬ȧ²»Ш²¹³¥ɨփ²¹³¥ֵΪ0
RTC_Handle.u32_CompensationValue = 0x05; // ¿ªʼʱ֓²¹³¥£¬ȧ²»Ш²¹³¥ɨփ²¹³¥ֵΪ0
HAL_RTC_Config(&RTC_Handle);
/* Set RTC Time¡¢Date */
gstr_Time_Set.u8_Hours = 0x12;
gstr_Time_Set.u8_Minutes = 0x30;
gstr_Time_Set.u8_Seconds = 0x00;
HAL_RTC_SetTime(&gstr_Time_Set);
gstr_Date_Set.u8_Year = 0x21;
gstr_Date_Set.u8_Month = RTC_MONTH_MARCH;
gstr_Date_Set.u8_Date = 0x20;
gstr_Date_Set.u8_WeekDay = RTC_WEEKDAY_FRIDAY;
HAL_RTC_SetDate(&gstr_Date_Set);
NVIC_ClearPendingIRQ(RTC_IRQn);
NVIC_EnableIRQ(RTC_IRQn);
__HAL_RTC_ENABLE_MIN_IT;
/* Config EXTI */
EXTI_Line_Handle.u32_Line = EXTI_LINE_17;
EXTI_Line_Handle.u32_Mode = EXTI_MODE_INTERRUPT;
EXTI_Line_Handle.u32_Trigger = EXTI_TRIGGER_RISING;
HAL_EXTI_SetConfigLine(&EXTI_Line_Handle);
while (1)
{
printfS("MCU Enter Lowpower, Wait RTC 1 Minute Wakeup MCU!\n");
System_Enter_Stop_Mode(MODE_WFI);
printfS("MCU is Runing \r\n");
System_Delay_MS(200);
printfS("MCU is Runing \r\n");
System_Delay_MS(200);
}
运行效果如图:
1.3.3. 对RTC电源域的GPIO(PC13/PC14/PC15)的特别处理
处于RTC电源域的GPIO(PC13/PC14/PC15),其设置需要额外多几个操作,参考RTC例程。 开发板的User Button连接到PC13上,因此以PC13为例,探讨使用PC13触发EXTI外部中断唤醒的操作。
case TEST_EXTI_PC13:
GPIO_InitTypeDef GPIO_PC13_Handler;
/* Initialization GPIO */
GPIO_PC13_Handler.Pin = GPIO_PIN_13;
GPIO_PC13_Handler.Mode = GPIO_MODE_INPUT;
GPIO_PC13_Handler.Pull = GPIO_PULLUP;
GPIO_PC13_Handler.Alternate = GPIO_FUNCTION_0;
HAL_GPIO_Init(GPIOC, &GPIO_PC13_Handler);
/* RTC access enable */
System_Enable_Disable_RTC_Domain_Access(FUNC_ENABLE);
__HAL_RTC_PC13_SEL(0); // GPIO function
__HAL_RTC_PC13_PULL_UP_ENABLE();
__HAL_RTC_PC13_DIGIT();
/* Config EXTI */
EXTI_Line_Handle.u32_Line = EXTI_LINE_13;
EXTI_Line_Handle.u32_Mode = EXTI_MODE_INTERRUPT;
EXTI_Line_Handle.u32_Trigger = EXTI_TRIGGER_FALLING;
EXTI_Line_Handle.u32_GPIOSel = EXTI_GPIOC;
HAL_EXTI_SetConfigLine(&EXTI_Line_Handle);
while (1)
{
printfS("MCU Enter Lowpower, Let PC13 Fall Down Wakeup MCU!\n");
System_Enter_Stop_Mode(MODE_WFI);
printfS("MCU is Runing \r\n");
System_Delay_MS(200);
printfS("MCU is Runing \r\n");
System_Delay_MS(200);
}
break;
运行效果如图,只需要按键即可唤醒MCU。
|