STM32 待机模式
所有导的包都是运行的以前发过的案例
#include "stm32f10x.h"
#include "usart1.h"
#include "delay.h"
#include <stdio.h>
#include "led.h"
#include "key.h"
#include "tim1.h"
void enter_standby_mode(void)
{
// 系统控制寄存器 Cortex_m3指南
SCB->SCR |= SCB_SCR_SLEEPDEEP;
// 使能PWR
RCC->APB1ENR |= RCC_APB1ENR_PWREN;
// 设置PDDS
PWR->CR |= PWR_CR_PDDS;
//设置待机的WAKEUP
PWR->CSR |= PWR_CSR_EWUP;
// 中断唤醒方式进入待机模式
__WFI();
}
int main()
{
//无论手动复位还是待机复位都会执行main()函数
//在main()中如何区分当前执行是手动复位还收待机复位
//PWR_CR.SBF ->区分手动复位(0)和待机复位(1)
//PWR_CR.WUF ->区分是不是由PA0_WAKEUP或RTC闹钟
//使能PWR
USART1_Init();
RCC->APB1ENR |= RCC_APB1ENR_PWREN;
//判断复位的来源
if(PWR->CSR & PWR_CSR_SBF){
printf("待机复位\n");
PWR->CR |= PWR_CR_CSBF;
}else{
printf("手动复位\n");
}
//判断复位方式
if(PWR->CSR & PWR_CSR_WUF)
{
PWR->CR |= PWR_CR_CWUF;
}
printf("SLEEP Model Test...\n");
TIM1_Init();
LED_Init();
KEY_Init();
LED_On(GPIO_ODR_ODR1);
printf("准备进入待机模式\n");
ready();
LED_Toggle(GPIO_ODR_ODR1);
printf("进入待机模式\n");
enter_standby_mode();
while (1)
{
delay_ms(1000);
}
}
更多推荐
所有评论(0)