stm32的低功耗,采用rtc的alarm唤醒,在唤醒之前所用的外设有uart,TIM2.当唤醒之后,首先我从新配置了时钟:代码 ErrorStatus HSEStartUpStatus; //turn on HSE RCC_HSEConfig(RCC_HSE_ON); //Wait till HSE is ready and if Time out is reached exit HSEStartUpStatus = RCC_WaitForHSEStartUp(); if(HSEStartUpStatus == SUCCESS) { /* Enable Prefetch Buffer */ FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable); /* Flash 2 wait state */ FLASH_SetLatency(FLASH_Latency_2); /* HCLK = SYSCLK */ RCC_HCLKConfig(RCC_SYSCLK_Div1); /* PCLK2 = HCLK */ RCC_PCLK2Config(RCC_HCLK_Div1); /* PCLK1 = HCLK/2 */ RCC_PCLK1Config(RCC_HCLK_Div2); /* PLLCLK = 8MHz * 9 = 72 MHz */ RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9); //enable PLL RCC_PLLCmd(ENABLE); //Wait till PLL is ready while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET) {} //Select PLL as system clock source RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK); //Wait till PLL is used as system clock source while(RCC_GetSYSCLKSource() != 0x08) {} } 这段代码应该没问题,以防万一,先贴出来。 之后如果去配置uart或者TIM2这些外设,使他们正常使用? |
板子开机 -> 按下PA1 -> 芯片进入stop模式 -> 按下PA1 -> 外部中断将芯片唤醒 。。。 程序处理如下: void EXTI0_1_IRQHandler(void) { if(EXTI_GetITStatus(EXTI_Line1)!= RESET ) { if(mcu_state == MCU_IS_RUNNING) mcu_state = MCU_IS_STOP; else if(mcu_state == MCU_IS_STOP) mcu_state = MCU_IS_RUNNING; b_mcu_exti_has_intterrupt = 1; EXTI_ClearITPendingBit(EXTI_Line1); } } 然后在main里面: void MCU_State_Change(void) { if(b_mcu_exti_has_intterrupt) { b_mcu_exti_has_intterrupt = 0; if(mcu_state == MCU_IS_RUNNING) { } else if(mcu_state == MCU_IS_STOP) { RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE); NVIC_SystemLPConfig(NVIC_LP_SLEEPDEEP,ENABLE); RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR,ENABLE); PWR_EnterSTOPMode(PWR_Regulator_LowPower,PWR_STOPEntry_WFI); } } } 现在发现两个问题: 1.感觉按键不是很灵敏,有时要按几下才能进入休眠,有时休眠要按几下才能唤醒,外部中断我仿真过,每次按下按键都能进到中断里面。 2.芯片进入stop模式之后被唤醒,时钟明显感觉变慢了,我在数码管上做了TIM16计数,我后来在: if(mcu_state == MCU_IS_RUNNING) { TIM16_For_Tick_Start(); /*开定时器*/ } |