STM32l053低功耗睡眠模式例程分析

最近研究STM32l053  nucleo开发板的睡眠模式例程配置。

main程序如下

int main(void)
{
  /* STM32L0xx HAL library initialization:
       - Configure the Flash prefetch, Flash preread and Buffer caches
       - Systick timer is configured by default as source of time base, but user 
             can eventually implement his proper time base source (a general purpose 
             timer for example or other time source), keeping in mind that Time base 
             duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and 
             handled in milliseconds basis.
       - Low Level Initialization
     */
  HAL_Init();

  /* 配置led2 用于出错闪烁 */
  BSP_LED_Init(LED2);

  /* 系统时钟16M */
  SystemClock_Config();

  /* 系统功耗 */
  SystemPower_Config();


Led_Config();//配置指示灯
  while (1)
  {
HAL_GPIO_WritePin(GPIOA,GPIO_PIN_5,GPIO_PIN_SET);//点亮
    /* Insert 5 seconds delay   5s延时*/
    HAL_Delay(5000);

    /* Key button (EXTI_Line13) 用来唤醒睡眠模式 */
    BSP_PB_Init(BUTTON_KEY, BUTTON_MODE_EXTI);
   
    /*挂起时钟以免唤醒. 否则系统滴答1ms唤醒一次
      Otherwise the Systick interrupt will wake up the device within 1ms (HAL time base)*/
    HAL_SuspendTick();
      HAL_GPIO_WritePin(GPIOA,GPIO_PIN_5,GPIO_PIN_RESET);//关掉led灯
    /* Enter Sleep Mode , wake up is done once Key push button is pressed 进入休眠等待唤醒*/
    HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI);
  
    /* Resume Tick interrupt if disabled prior to sleep mode entry  恢复中断*/
    HAL_ResumeTick();
  }
}

该例程 展示了如何让系统进入睡眠模式,以及通过按键唤醒的例子。

同时也可以在睡眠模式下测试低功耗电流。

软件设置为16MHZ,1ms一个中断。

按键被配置为外部触发模式。

我用一个led灯指示,上电后led灯亮,5s中后灭进入睡眠。按一下按键灯又亮说明被唤醒。

将资料包代替官方的文件夹就可以用了

下载地址 链接:http://pan.baidu.com/s/1dEhIH6D 密码:heyg

最新评论

  1. 发布于:2020-12-15 14:52 回复
    天龙开区-机器人车技发网最好的游戏

sitemap