微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > STM32f103-实例睡眠模式的唤醒

STM32f103-实例睡眠模式的唤醒

时间:11-17 来源:互联网 点击:

*****************************
* Function Name : GPIO_Configuration();
* Description : GPIO SET
* Input : nCount: None
* Output : None
* Return : None
*******************************************************************************/
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_10 | GPIO_Pin_11|GPIO_Pin_12 | GPIO_Pin_12 | GPIO_Pin_13| GPIO_Pin_14|GPIO_Pin_15;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);//GPIO_InitStructure指向了GPIO_InitTypeDef ,GPIO_InitTypeDef结构体包含了基本信息

/* Configure Key Button GPIO Pin as input floating (Key Button EXTI Line) */

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOB, &GPIO_InitStructure);
}
/*******************************************************************************
* Function Name : GPIO_Configuration();
* Description : GPIO SET
* Input : nCount: None
* Output : None
* Return : None
*******************************************************************************/
void EXTI_Configuration(void)
{
EXTI_InitTypeDef EXTI_InitStructure;
GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource5);
/* Configure Key Button EXTI Line to generate an interrupt on falling edge */
EXTI_InitStructure.EXTI_Line = EXTI_Line5;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);

/*配置EXTI_Line17(RTC_Alarm)为上升沿触发*/
EXTI_ClearITPendingBit(EXTI_Line17);
EXTI_InitStructure.EXTI_Line = EXTI_Line17 ;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
EXTI_Init(&EXTI_InitStructure);

}

/*******************************************************************************
* Function Name : RTC_Configuration
* Description : PTC_clclk
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void RTC_Configuration (void)
{
/*配置RTC时钟源*/
/* 允许访问BKP*/
PWR_BackupAccessCmd(ENABLE);
/*复位备份域*/
BKP_DeInit();
/*允许LSE*/
RCC_LSEConfig(RCC_LSE_ON);
/*等待LSE有效*/
while (RCC_GetFlagStatus(RCC_FLAG_LSERDY)==RESET) ;
/*选择LSE做为RTC时钟 */
RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);
/*允许RTC时钟*/
RCC_RTCCLKCmd(ENABLE);

/*配置RTC*/
/*等待RTC APB同步*/
RTC_WaitForSynchro();

/*预分频值为1s*/

RTC_SetPrescaler(32767);

/*等待最后一条写指令完成*/

RTC_WaitForLastTask();

/*允许RTC报警中断*/
RTC_ITConfig(RTC_IT_ALR, ENABLE);

/*等待最后一条写指令完成*/
RTC_WaitForLastTask();
}

/*******************************************************************************
* Function Name : NVIC_Configuration
* Description : Configures Vector Table base location.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStruct;
/*设置中断向量基址为0x8000000*/
NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);

NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);

NVIC_InitStruct.NVIC_IRQChannel= RTCAlarm_IRQChannel ;
NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority= 0;
NVIC_InitStruct.NVIC_IRQChannelSubPriority= 0;
NVIC_InitStruct.NVIC_IRQChannelCmd= ENABLE;
NVIC_Init(&NVIC_InitStruct);

NVIC_InitStruct.NVIC_IRQChannel= EXTI9_5_IRQChannel ;
NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority= 0;
NVIC_Init(&NVIC_InitStruct);

}

/*******************************************************************************
* Function Name : SysTick_Configuration
* Description : 配置1ms时钟
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void SysTick_Configuration(void)
{
/*选择HCLK做为SysTick时钟源 */
SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK);
/*_SysTick设置为优先级3 */
NVIC_SystemHandlerPriorityConfig (SystemHandler_SysTick, 3,0 );
/*1ms发生1次SysTick中断对应HCLK为72MHZ */
SysTick_SetReload(72000);
/* 允许SysTick中断*/
SysTick_ITConfig(ENABLE);
}

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top