本帖最后由 lusson 于 2014-5-30 10:07 编辑
STM32F407,使用了狗立看门狗,测试低功耗模式。
STOP模式,用systick唤不醒,所以得改用RTC唤醒,目前设置在256ms唤醒一次,唤醒后跑一遍必要的程序后重新进入STOP。LSI给RTC提供时钟,看门狗设置2S溢出,关SYSTICK,除了需要的2个输出IO,其他全部设置在IN 下拉模式,目前电流是在300uA,唤醒后把KEY输入重新配置为输入上拉,再读取KEY。所有未使用IO线唤醒模式
硬件如下:
电池:单芯锂电池
充电:BQ24073
升压:TPS63000 (输出3.3V)
LDO:XC6206-3.0 (待机时供电)
-----------------------------------
注意几点:
1.网上说的IO设置在AIN最小并不真实,应该设置在IN模式并且下拉(一定要下拉,不下拉功耗增加非常多) AIN时在1mA,IN下拉时目前在300uA
主要程序如下:
RTC设置程序:
- static void RTC_Configuration(void)
- {
- RTC_InitTypeDef RTC_InitStructure;
-
- /*Enable PWR and BKP clocks */
- RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
- /*Allow access to BKP Domain */
- PWR_BackupAccessCmd(ENABLE);
- /*Enable LSI */
- RCC_HSICmd(ENABLE);
- /*Wait till LSI is ready */
- while (RCC_GetFlagStatus(RCC_FLAG_LSIRDY) == RESET);
- /*Select LSI as RTC Clock Source */
- RCC_RTCCLKConfig(RCC_RTCCLKSource_LSI);
- /*Enable RTC Clock */
- RCC_RTCCLKCmd(ENABLE);
- /*Wait for RTC registers synchronization */
- RTC_WaitForSynchro();
- /*RTC Init */
- RTC_InitStructure.RTC_HourFormat= RTC_HourFormat_24; //24 hour format
- //32768/ (1 + 0x7F) = 32768 /128 = 256Hz,
- //256/ (1 + 63) = 4Hz, This is the calender frequecy~
- RTC_InitStructure.RTC_SynchPrediv= 63;
- RTC_InitStructure.RTC_AsynchPrediv= 0x7F;
- RTC_Init(&RTC_InitStructure);
- /*NVIC configuration */
- RTC_NVIC_Configuration();
- RTC_WakeUpCmd(DISABLE); //important
- //Configure the RTC WakeUp Clock source: CK_SPRE (1Hz)
- RTC_WakeUpClockConfig(RTC_WakeUpClock_CK_SPRE_16bits);
- RTC_SetWakeUpCounter(0x0);
- RTC_WakeUpCmd(ENABLE);
- RTC_ClearITPendingBit(RTC_IT_WUT);
- RTC_ITConfig(RTC_IT_WUT,ENABLE);
- }
复制代码
RTC中断及中断配置程序
- void RTC_WKUP_IRQHandler(void)
- {
- RTC_ClearITPendingBit(RTC_IT_WUT);
- EXTI_ClearITPendingBit(EXTI_Line22);
- }
- static void RTC_NVIC_Configuration(void)
- {
- NVIC_InitTypeDef NVIC_InitStructure;
- EXTI_InitTypeDef EXTI_InitStructure;
- /*EXTI Configuration */
- EXTI_ClearITPendingBit(EXTI_Line22);
- EXTI_InitStructure.EXTI_Line= EXTI_Line22;
- EXTI_InitStructure.EXTI_Mode= EXTI_Mode_Interrupt;
- EXTI_InitStructure.EXTI_Trigger= EXTI_Trigger_Rising;
- EXTI_InitStructure.EXTI_LineCmd= ENABLE;
- EXTI_Init(&EXTI_InitStructure);
- /*Configure one bit for preemption priority */
- NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
- /*Enable the RTC Interrupt */
- NVIC_InitStructure.NVIC_IRQChannel = RTC_WKUP_IRQn;
- NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
- NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
- NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
- NVIC_Init(&NVIC_InitStructure);
- }
复制代码
主程序(break表示检测到POWER长押,开机,往下走到正常速度的程序):
- RTC_Configuration();
- PWR_FlashPowerDownCmd(ENABLE);
- while(1){
- key_slowtimer_task(SLOW_SLOT_TIME/SLOT_TIME);
- key_long_task();
- key_decode();
- power_long_task();
- wdt_long_task();
- if ( power_ctrl_status_get() == 1 ){
- RCC_RTCCLKCmd(DISABLE);
- break;
- }
- applihand_enter_low_power();
- PWR_FlashPowerDownCmd(ENABLE);
- PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI);
- applihand_wake_power();
- }
复制代码
一周热门 更多>