电流
直播中

世态薄凉

9年用户 1243经验值
私信 关注
[问答]

STM32L151C8T6低功耗编程代码该如何去编写

STM32L151C8T6低功耗编程代码该如何去编写?

回帖(1)

朱瑞平

2021-10-14 10:32:30
  条件:
  STM32L151C8T6 全部端口悬空 电源电压 2.8V 供电 使用内部时钟64k
  //单片机 STM32L151C8T6
  //keil4
  //运行时的 电流是 140uA
  //stop模式的 电流是 20uA
  //编译不通过 查询 固件库
  int main()
  {
  Delay_ms(1000);
  HSI_init();//设置系统时钟 MSI clock is around 65.536 KHz
  clock_out();//使用 PA8口 输出系统时钟
  Delay_ms(10);//时钟输出一会
  gpio_lowpower_fun();//22uA
  PWR_EnterSTOPMode(PWR_Regulator_ON,PWR_STOPEntry_WFE);//进入stop模式
  while(1)
  {
  }
  }
  void Delay_ms(uint16_t time_ms)
  {
  uint16_t i,j;
  i = time_ms;
  while(i!=0)
  {
  for( j=0;j《8000;j++ )
  {}
  i--;
  }
  }
  void HSI_init(void)//MSI clock is around 65.536 KHz
  {
  RCC_DeInit();
  RCC_MSIRangeConfig(RCC_MSIRange_0);
  while(RCC_GetFlagStatus(RCC_FLAG_HSERDY)!=RESET)
  {}
  }
  void clock_out(void)//使用PA8输出 系统时钟 便于观察系统时钟
  {
  GPIO_InitTypeDef GPIO_InitStructure;
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  GPIO_Init(GPIOA, &GPIO_InitStructure);
  RCC_MCOConfig(RCC_MCOSource_SYSCLK,RCC_MCODiv_1);
  }
  void gpio_lowpower_fun(void)
  {
  GPIO_InitTypeDef GPIO_InitStructure;
  RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOA, DISABLE);
  RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOB, DISABLE);
  RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOC, DISABLE);
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_400KHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;
  GPIO_Init(GPIOA, &GPIO_InitStructure);
  GPIO_Init(GPIOB, &GPIO_InitStructure);
  GPIO_Init(GPIOC, &GPIO_InitStructure);
  }
举报

更多回帖

发帖
×
20
完善资料,
赚取积分