【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

相关文章

SQL Server修改数据库名及物理数据文件名操作步骤

《SQLServer修改数据库名及物理数据文件名操作步骤》在SQLServer中重命名数据库是一个常见的操作,但需要确保用户具有足够的权限来执行此操作,:本文主要介绍SQLServer修改数据... 目录一、背景介绍二、操作步骤2.1 设置为单用户模式(断开连接)2.2 修改数据库名称2.3 查找逻辑文件名

Redis Cluster模式配置

《RedisCluster模式配置》:本文主要介绍RedisCluster模式配置,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧... 目录分片 一、分片的本质与核心价值二、分片实现方案对比 ‌三、分片算法详解1. ‌范围分片(顺序分片)‌2. ‌哈希分片3. ‌虚

Go学习记录之runtime包深入解析

《Go学习记录之runtime包深入解析》Go语言runtime包管理运行时环境,涵盖goroutine调度、内存分配、垃圾回收、类型信息等核心功能,:本文主要介绍Go学习记录之runtime包的... 目录前言:一、runtime包内容学习1、作用:① Goroutine和并发控制:② 垃圾回收:③ 栈和

Oracle修改端口号之后无法启动的解决方案

《Oracle修改端口号之后无法启动的解决方案》Oracle数据库更改端口后出现监听器无法启动的问题确实较为常见,但并非必然发生,这一问题通常源于​​配置错误或环境冲突​​,而非端口修改本身,以下是系... 目录一、问题根源分析​​​二、保姆级解决方案​​​​步骤1:修正监听器配置文件 (listener.

Linux中修改Apache HTTP Server(httpd)默认端口的完整指南

《Linux中修改ApacheHTTPServer(httpd)默认端口的完整指南》ApacheHTTPServer(简称httpd)是Linux系统中最常用的Web服务器之一,本文将详细介绍如何... 目录一、修改 httpd 默认端口的步骤1. 查找 httpd 配置文件路径2. 编辑配置文件3. 保存

Android学习总结之Java和kotlin区别超详细分析

《Android学习总结之Java和kotlin区别超详细分析》Java和Kotlin都是用于Android开发的编程语言,它们各自具有独特的特点和优势,:本文主要介绍Android学习总结之Ja... 目录一、空安全机制真题 1:Kotlin 如何解决 Java 的 NullPointerExceptio

RabbitMQ工作模式中的RPC通信模式详解

《RabbitMQ工作模式中的RPC通信模式详解》在RabbitMQ中,RPC模式通过消息队列实现远程调用功能,这篇文章给大家介绍RabbitMQ工作模式之RPC通信模式,感兴趣的朋友一起看看吧... 目录RPC通信模式概述工作流程代码案例引入依赖常量类编写客户端代码编写服务端代码RPC通信模式概述在R

Nginx 413修改上传文件大小限制的方法详解

《Nginx413修改上传文件大小限制的方法详解》在使用Nginx作为Web服务器时,有时会遇到客户端尝试上传大文件时返回​​413RequestEntityTooLarge​​... 目录1. 理解 ​​413 Request Entity Too Large​​ 错误2. 修改 Nginx 配置2.1

SQL Server身份验证模式步骤和示例代码

《SQLServer身份验证模式步骤和示例代码》SQLServer是一个广泛使用的关系数据库管理系统,通常使用两种身份验证模式:Windows身份验证和SQLServer身份验证,本文将详细介绍身份... 目录身份验证方式的概念更改身份验证方式的步骤方法一:使用SQL Server Management S

Python对PDF书签进行添加,修改提取和删除操作

《Python对PDF书签进行添加,修改提取和删除操作》PDF书签是PDF文件中的导航工具,通常包含一个标题和一个跳转位置,本教程将详细介绍如何使用Python对PDF文件中的书签进行操作... 目录简介使用工具python 向 PDF 添加书签添加书签添加嵌套书签Python 修改 PDF 书签Pytho