中级会员
 
- 积分
- 350
- 金钱
- 350
- 注册时间
- 2015-7-14
- 在线时间
- 76 小时
|

楼主 |
发表于 2019-10-20 16:17:13
|
显示全部楼层
再贴上代码:
int main(void)
{
uint16_t main_state;
PRIORITY_GROUP_SET(NVIC_PriorityGroup_0);
BSP_IwdgInit();
BSP_TMR_Init();
BSP_LED_Init();
BSP_USART_Init();
BSP_STMR_Auto_Start(2, 50);
BSP_VGPRSPower_CTRL(DISABLE);
// BSP_AIR208Init();
// AIR208_PowerOn();
BSP_RTC_WKUP_Init(5);
PWR_EnterSTOPMode(PWR_Regulator_LowPower,PWR_STOPEntry_WFI);
while (1)
{
/*系统运行指示灯*/
if(BSP_STMR_Check(2))
{
BSP_IwdgFeed();
BSP_LED_Toggle();
BSP_STMR_Auto_Start(2, 50); //将软件定时器3专用于LED闪烁
}
}
}
void BSP_RTC_WKUP_Config(uint32_t RTC_WakeUpCounter)
{
NVIC_InitTypeDef NVIC_InitStructure;
EXTI_InitTypeDef EXTI_InitStructure;
/* Enable the PWR clock */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
/* Allow access to RTC */
PWR_RTCAccessCmd(ENABLE);
/* LSI used as RTC source clock */
/* The RTC Clock may varies due to LSI frequency dispersion. */
/* Enable the LSI OSC */
RCC_LSICmd(ENABLE);
/* Wait till LSI is ready */
while(RCC_GetFlagStatus(RCC_FLAG_LSIRDY) == RESET){}
/* Select the RTC Clock Source */
RCC_RTCCLKConfig(RCC_RTCCLKSource_LSI);
/* Enable the RTC Clock */
RCC_RTCCLKCmd(ENABLE);
/* Wait for RTC APB registers synchronisation */
RTC_WaitForSynchro();
/* EXTI configuration */
EXTI_ClearITPendingBit(EXTI_Line20); //配置RTC_WKUP中断
EXTI_InitStructure.EXTI_Line = EXTI_Line20;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
/* Enable the RTC Wakeup Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = RTC_WKUP_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
/* Configure the RTC WakeUp Clock source: CK_SPRE (1Hz) */
RTC_WakeUpClockConfig(RTC_WakeUpClock_CK_SPRE_16bits);
RTC_SetWakeUpCounter(RTC_WakeUpCounter);
/* Enable the RTC Wakeup Interrupt */
RTC_ITConfig(RTC_IT_WUT, ENABLE);
/* Enable Wakeup Counter */
RTC_WakeUpCmd(ENABLE);
}
/**
* @brief 该函数用于初始化RTC_WKUP功能
* @param RTC_WakeUpCounter:RTC唤醒计数器
* @retval 无
*/
void BSP_RTC_WKUP_Init(uint32_t RTC_WakeUpCounter)
{
RTC_InitTypeDef RTC_InitStructure;
BSP_RTC_WKUP_Config(RTC_WakeUpCounter);
RTC_InitStructure.RTC_AsynchPrediv = 0x7F;
RTC_InitStructure.RTC_SynchPrediv = 255;
RTC_InitStructure.RTC_HourFormat = RTC_HourFormat_24;
RTC_Init(&RTC_InitStructure);
}
/**
* @brief RTC_WKUP中断处理函数
* @param 无
* @retval 无
*/
void RTC_WKUP_IRQHandler(void)
{
if(RTC_GetITStatus(RTC_IT_WUT) != RESET)
{
RTC_ClearITPendingBit(RTC_IT_WUT);
EXTI_ClearITPendingBit(EXTI_Line20);
/** @note
* 由于STOP被唤醒后,系统自动切换至HSI时钟。需重新初始化RCC时钟
*/
SystemInit();
/*唤醒后立即喂狗*/
BSP_IwdgFeed();
}
}
|
|