【STM32】STM32学习笔记-修改主频 睡眠模式 停止模式 待机模式(45)

2024-02-28 20:44

本文主要是介绍【STM32】STM32学习笔记-修改主频 睡眠模式 停止模式 待机模式(45),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

00. 目录

文章目录

    • 00. 目录
    • 01. PWR简介
    • 02. 修改主频接线图
    • 03. 修改主频相关API
    • 04. 修改主频程序示例
    • 05. 睡眠模式接线图
    • 06. 睡眠模式相关API
    • 07. 睡眠模式程序示例
    • 08. 停止模式接线图
    • 09. 停止模式相关API
    • 10. 停止模式程序示例
    • 11. 待机模式接线图
    • 12. 待机模式相关API
    • 13. 待机模式程序示例
    • 14. 示例程序下载
    • 15. 附录

01. PWR简介

  • PWR(Power Control)电源控制

  • PWR负责管理STM32内部的电源供电部分,可以实现可编程电压监测器和低功耗模式的功能

  • 可编程电压监测器(PVD)可以监控VDD电源电压,当VDD下降到PVD阀值以下或上升到PVD阀值之上时,PVD会触发中断,用于执行紧急关闭任务

  • 低功耗模式包括睡眠模式(Sleep)、停机模式(Stop)和待机模式(Standby),可在系统空闲时,降低STM32的功耗,延长设备使用时间

02. 修改主频接线图

在这里插入图片描述

03. 修改主频相关API

  /******************************************************************************* @file    system_stm32f10x.c* @author  MCD Application Team* @version V3.5.0* @date    11-March-2011* @brief   CMSIS Cortex-M3 Device Peripheral Access Layer System Source File.* * 1.  This file provides two functions and one global variable to be called from *     user application:*      - SystemInit(): Setups the system clock (System clock source, PLL Multiplier*                      factors, AHB/APBx prescalers and Flash settings). *                      This function is called at startup just after reset and *                      before branch to main program. This call is made inside*                      the "startup_stm32f10x_xx.s" file.**      - SystemCoreClock variable: Contains the core clock (HCLK), it can be used*                                  by the user application to setup the SysTick *                                  timer or configure other parameters.*                                     *      - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must*                                 be called whenever the core clock is changed*                                 during program execution.** 2. After each device reset the HSI (8 MHz) is used as system clock source.*    Then SystemInit() function is called, in "startup_stm32f10x_xx.s" file, to*    configure the system clock before to branch to main program.** 3. If the system clock source selected by user fails to startup, the SystemInit()*    function will do nothing and HSI still used as system clock source. User can *    add some code to deal with this issue inside the SetSysClock() function.** 4. The default value of HSE crystal is set to 8 MHz (or 25 MHz, depedning on*    the product used), refer to "HSE_VALUE" define in "stm32f10x.h" file. *    When HSE is used as system clock source, directly or through PLL, and you*    are using different crystal you have to adapt the HSE value to your own*    configuration.*        ******************************************************************************/

修改主频的方法

system_stm32f10x.c 106行

#if defined (STM32F10X_LD_VL) || (defined STM32F10X_MD_VL) || (defined STM32F10X_HD_VL)
/* #define SYSCLK_FREQ_HSE    HSE_VALUE */#define SYSCLK_FREQ_24MHz  24000000
#else
/* #define SYSCLK_FREQ_HSE    HSE_VALUE */
/* #define SYSCLK_FREQ_24MHz  24000000 */ #define SYSCLK_FREQ_36MHz  36000000 
/* #define SYSCLK_FREQ_48MHz  48000000 */
/* #define SYSCLK_FREQ_56MHz  56000000 */
//#define SYSCLK_FREQ_72MHz  72000000
#endif

04. 修改主频程序示例

main.c

#include "stm32f10x.h"#include "delay.h"
#include "oled.h"int main(void){	//初始化OLED_Init();
#if 0//显示一个字符OLED_ShowChar(1, 1, 'A');//显示字符串OLED_ShowString(1, 3, "HelloWorld!");//显示十进制数字OLED_ShowNum(2, 1, 12345, 5);//显示有符号十进制数OLED_ShowSignedNum(2, 7, -66, 2);//显示十六进制OLED_ShowHexNum(3, 1, 0xAA55, 4);//显示二进制数字OLED_ShowBinNum(4, 1, 0xAA55, 16);
#endifOLED_ShowString(1, 1, "SYSCLK:");OLED_ShowNum(1, 8, SystemCoreClock, 8);while(1){OLED_ShowString(2, 1, "Running");delay_ms(500);OLED_ShowString(2, 1, "       ");		 delay_ms(500);	 	 }return 0;}

05. 睡眠模式接线图

在这里插入图片描述

06. 睡眠模式相关API

#define __NOP                             __nop
#define __WFI                             __wfi
#define __WFE                             __wfe

07. 睡眠模式程序示例

main.c

#include "stm32f10x.h"
#include <stdio.h>
#include "delay.h"
#include "oled.h"
#include "uart.h"int main(void){	uint16_t data = 0;OLED_Init();uart_init();//中断分组NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);OLED_ShowChar(1, 1, 'A');while(1){if (1 == uart_getRxFlag()){data = uart_getRxData();uart_send_byte(data);OLED_ShowHexNum(1, 1, data, 2);}OLED_ShowString(2, 1, "Running");delay_ms(100);OLED_ShowString(2, 1, "       ");		 delay_ms(100);	//进入睡眠模式__WFI();}return 0;}

08. 停止模式接线图

在这里插入图片描述

09. 停止模式相关API

RCC_APB1PeriphClockCmd函数

/*** @brief  Enables or disables the Low Speed APB (APB1) peripheral clock.* @param  RCC_APB1Periph: specifies the APB1 peripheral to gates its clock.*   This parameter can be any combination of the following values:*     @arg RCC_APB1Periph_TIM2, RCC_APB1Periph_TIM3, RCC_APB1Periph_TIM4,*          RCC_APB1Periph_TIM5, RCC_APB1Periph_TIM6, RCC_APB1Periph_TIM7,*          RCC_APB1Periph_WWDG, RCC_APB1Periph_SPI2, RCC_APB1Periph_SPI3,*          RCC_APB1Periph_USART2, RCC_APB1Periph_USART3, RCC_APB1Periph_USART4, *          RCC_APB1Periph_USART5, RCC_APB1Periph_I2C1, RCC_APB1Periph_I2C2,*          RCC_APB1Periph_USB, RCC_APB1Periph_CAN1, RCC_APB1Periph_BKP,*          RCC_APB1Periph_PWR, RCC_APB1Periph_DAC, RCC_APB1Periph_CEC,*          RCC_APB1Periph_TIM12, RCC_APB1Periph_TIM13, RCC_APB1Periph_TIM14* @param  NewState: new state of the specified peripheral clock.*   This parameter can be: ENABLE or DISABLE.* @retval None*/
void RCC_APB1PeriphClockCmd(uint32_t RCC_APB1Periph, FunctionalState NewState)
功能:使能或者失能 APB1 外设时钟
参数:RCC_APB1Periph: 门控 APB1 外设时钟NewState:指定外设时钟的新状态,这个参数可以取:ENABLE 或者 DISABLE
返回值:

PWR_EnterSTOPMode函数

/*** @brief  Enters STOP mode.* @param  PWR_Regulator: specifies the regulator state in STOP mode.*   This parameter can be one of the following values:*     @arg PWR_Regulator_ON: STOP mode with regulator ON*     @arg PWR_Regulator_LowPower: STOP mode with regulator in low power mode* @param  PWR_STOPEntry: specifies if STOP mode in entered with WFI or WFE instruction.*   This parameter can be one of the following values:*     @arg PWR_STOPEntry_WFI: enter STOP mode with WFI instruction*     @arg PWR_STOPEntry_WFE: enter STOP mode with WFE instruction* @retval None*/
void PWR_EnterSTOPMode(uint32_t PWR_Regulator, uint8_t PWR_STOPEntry)
功能:进入停止(STOP)模式
参数:PWR_Regulator: 电压转换器在停止模式下的状态PWR_STOPEntry: 选择使用指令 WFE 还是 WFI 来进入停止模式
返回值:

10. 停止模式程序示例

main.c

#include "stm32f10x.h"#include "delay.h"
#include "oled.h"
#include "CountSensor.h"int main(void){		 //初始化OLED_Init();//开启PWR时钟RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);OLED_ShowString(1, 1, "Count:");NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);count_sensor_init();while(1){OLED_ShowNum(1 , 7, CountSensor_Get(), 5);OLED_ShowString(2, 1, "Running");delay_ms(100);OLED_ShowString(2, 1, "       ");		 delay_ms(100);	//进入停止模式PWR_EnterSTOPMode(PWR_Regulator_ON, PWR_STOPEntry_WFI);//系统重新初始化SystemInit();}return 0;}

11. 待机模式接线图

在这里插入图片描述

12. 待机模式相关API

PWR_EnterSTANDBYMode函数

/*** @brief  Enters STANDBY mode.* @param  None* @retval None*/
void PWR_EnterSTANDBYMode(void)
功能:进入待机(STANDBY)模式
参数:返回值:

PWR_WakeUpPinCmd函数

/*** @brief  Enables or disables the WakeUp Pin functionality.* @param  NewState: new state of the WakeUp Pin functionality.*   This parameter can be: ENABLE or DISABLE.* @retval None*/
void PWR_WakeUpPinCmd(FunctionalState NewState)
功能:使能或者失能唤醒管脚功能
参数:NewState: 唤醒管脚功能的新状态,这个参数可以取:ENABLE 或者 DISABLE
返回值:  

13. 待机模式程序示例

main.c

#include "stm32f10x.h"
#include "delay.h"
#include "oled.h"
#include "key.h"
#include "rtc.h"int main(void){	uint32_t alarm = 0;//初始化OLED_Init();key_init();rtc_init();//开启PWR时钟RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);OLED_ShowString(1, 1, "CNT: ");OLED_ShowString(2, 1, "ALR: ");OLED_ShowString(3, 1, "ALRF: ");PWR_WakeUpPinCmd(ENABLE);alarm = RTC_GetCounter() + 10;RTC_SetAlarm(alarm);OLED_ShowNum(2, 6, alarm, 10);while(1){	 			OLED_ShowNum(1, 6, RTC_GetCounter(), 10);	//显示32位的秒计数器		OLED_ShowNum(3, 6, RTC_GetFlagStatus(RTC_FLAG_ALR), 1);OLED_ShowString(4, 1, "Running");delay_ms(100);OLED_ShowString(4, 1, "       ");		 delay_ms(1000);	 OLED_ShowString(4, 9, "STANDBY");delay_ms(100);OLED_ShowString(4, 9, "       ");		 delay_ms(100);	 OLED_Clear();PWR_EnterSTANDBYMode();}return 0;}

14. 示例程序下载

34-修改主频.rar

35-睡眠模式-UART发送和接收.rar

36-停止模式-对射式红外传感器计次.rar

37-待机模式-实时时钟.rar

15. 附录

参考: 【STM32】江科大STM32学习笔记汇总

这篇关于【STM32】STM32学习笔记-修改主频 睡眠模式 停止模式 待机模式(45)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/756564

相关文章

Java深度学习库DJL实现Python的NumPy方式

《Java深度学习库DJL实现Python的NumPy方式》本文介绍了DJL库的背景和基本功能,包括NDArray的创建、数学运算、数据获取和设置等,同时,还展示了如何使用NDArray进行数据预处理... 目录1 NDArray 的背景介绍1.1 架构2 JavaDJL使用2.1 安装DJL2.2 基本操

修改若依框架Token的过期时间问题

《修改若依框架Token的过期时间问题》本文介绍了如何修改若依框架中Token的过期时间,通过修改`application.yml`文件中的配置来实现,默认单位为分钟,希望此经验对大家有所帮助,也欢迎... 目录修改若依框架Token的过期时间修改Token的过期时间关闭Token的过期时js间总结修改若依

MySQL修改密码的四种实现方式

《MySQL修改密码的四种实现方式》文章主要介绍了如何使用命令行工具修改MySQL密码,包括使用`setpassword`命令和`mysqladmin`命令,此外,还详细描述了忘记密码时的处理方法,包... 目录mysql修改密码四种方式一、set password命令二、使用mysqladmin三、修改u

Java实现状态模式的示例代码

《Java实现状态模式的示例代码》状态模式是一种行为型设计模式,允许对象根据其内部状态改变行为,本文主要介绍了Java实现状态模式的示例代码,文中通过示例代码介绍的非常详细,需要的朋友们下面随着小编来... 目录一、简介1、定义2、状态模式的结构二、Java实现案例1、电灯开关状态案例2、番茄工作法状态案例

使用Python在Excel中插入、修改、提取和删除超链接

《使用Python在Excel中插入、修改、提取和删除超链接》超链接是Excel中的常用功能,通过点击超链接可以快速跳转到外部网站、本地文件或工作表中的特定单元格,有效提升数据访问的效率和用户体验,这... 目录引言使用工具python在Excel中插入超链接Python修改Excel中的超链接Python

python修改字符串值的三种方法

《python修改字符串值的三种方法》本文主要介绍了python修改字符串值的三种方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学... 目录第一种方法:第二种方法:第三种方法:在python中,字符串对象是不可变类型,所以我们没办法直接

python写个唤醒睡眠电脑的脚本

《python写个唤醒睡眠电脑的脚本》这篇文章主要为大家详细介绍了如何使用python写个唤醒睡眠电脑的脚本,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 环境:win10python3.12问题描述:怎么用python写个唤醒睡眠电脑的脚本?解决方案:1.唤醒处于睡眠状

Mysql8.0修改配置文件my.ini的坑及解决

《Mysql8.0修改配置文件my.ini的坑及解决》使用记事本直接编辑my.ini文件保存后,可能会导致MySQL无法启动,因为MySQL会以ANSI编码读取该文件,解决方法是使用Notepad++... 目录Myhttp://www.chinasem.cnsql8.0修改配置文件my.ini的坑出现的问题

HarmonyOS学习(七)——UI(五)常用布局总结

自适应布局 1.1、线性布局(LinearLayout) 通过线性容器Row和Column实现线性布局。Column容器内的子组件按照垂直方向排列,Row组件中的子组件按照水平方向排列。 属性说明space通过space参数设置主轴上子组件的间距,达到各子组件在排列上的等间距效果alignItems设置子组件在交叉轴上的对齐方式,且在各类尺寸屏幕上表现一致,其中交叉轴为垂直时,取值为Vert

Ilya-AI分享的他在OpenAI学习到的15个提示工程技巧

Ilya(不是本人,claude AI)在社交媒体上分享了他在OpenAI学习到的15个Prompt撰写技巧。 以下是详细的内容: 提示精确化:在编写提示时,力求表达清晰准确。清楚地阐述任务需求和概念定义至关重要。例:不用"分析文本",而用"判断这段话的情感倾向:积极、消极还是中性"。 快速迭代:善于快速连续调整提示。熟练的提示工程师能够灵活地进行多轮优化。例:从"总结文章"到"用