stm32進入停止模式,中斷 喚醒
1、程式說明:
a、此程式基於HY-STM32開發板。
b、自動進入停止模式
c、按鍵中斷實現喚醒
2、完整工程網址
a、基於iar軟體
http://download.csdn.net/detail/caojunjun12345/7554737
b、基於keil軟體
http://download.csdn.net/detail/caojunjun12345/7554749
3、main檔案內容
#include "BSP.h"
void RCC_Configuration(void);
void GPIO_Configuration(void);
void EXTI_Configuration(void);
void RTC_Configuration(void);
void NVIC_Configuration(void);
int main(void)
{
RCC_Configuration();
NVIC_Configuration();
GPIO_Configuration();
EXTI_Configuration();
while (1)
{
GPIO_WriteBit(GPIOC, GPIO_Pin_6,(BitAction)1);//置1
Delay(1000);
GPIO_WriteBit(GPIOC, GPIO_Pin_6,(BitAction)0);//置0
Delay(1000);
PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI);//進入停止模式
GPIO_WriteBit(GPIOC, GPIO_Pin_6,(BitAction)1);//置1
Delay(1000);
GPIO_WriteBit(GPIOC, GPIO_Pin_6,(BitAction)0);//置0
Delay(1000);
}
}
void RCC_Configuration(void)
{
SystemInit();
}
void GPIO_Configuration()
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd( RCC_APB2Periph_AFIO| RCC_APB2Periph_GPIOC
| RCC_APB2Periph_GPIOD |RCC_APB2Periph_GPIOE , ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6|GPIO_Pin_7;//D1 D2
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOC, &GPIO_InitStructure);
/* Configure PE4 as input floating (EXTI Line4) */ //KEY2
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOE, &GPIO_InitStructure);
}
/*******************************************************************************
* Function Name : NVIC_Configuration
* Description : Configures NVIC and Vector Table base location.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
#ifdef VECT_TAB_RAM
/* Set the Vector Table base location at 0x20000000 */
NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0);
#else /* VECT_TAB_FLASH */
/* Set the Vector Table base location at 0x08000000 */
NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);
#endif
/* Configure one bit for preemption priority */
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
//KEY2
NVIC_InitStructure.NVIC_IRQChannel = EXTI4_IRQChannel;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
void EXTI_Configuration(void)
{
EXTI_InitTypeDef EXTI_InitStructure;
GPIO_EXTILineConfig(GPIO_PortSourceGPIOE, GPIO_PinSource4);
//KEY2
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);
}
//KEY2按下,退出停止模式
void EXTI4_IRQHandler(void)
{
if(EXTI_GetITStatus(EXTI_Line4) != RESET)
{
EXTI_ClearITPendingBit(EXTI_Line4);
RCC_Configuration();//時鐘初始化
Delay(100);
}
}