#include "stm32f10x_bkp.h"
#include "stm32f10x_pwr.h"
#include "lora_app.h"
#include "pwr_pvd.h"
#include "led.h"
void PWR_PVD_Init(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
EXTI_InitTypeDef EXTI_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);//使能PWR时钟
NVIC_InitStructure.NVIC_IRQChannel = PVD_IRQn; //使能PVD所在的外部中断通道
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;//抢占优先级1
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; //子优先级0
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //使能外部中断通道
NVIC_Init(&NVIC_InitStructure);
EXTI_StructInit(&EXTI_InitStructure);
EXTI_InitStructure.EXTI_Line = EXTI_Line16; //PVD连接到中断线16上
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; //使用中断模式
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; //电压低于阀值时产生中断
EXTI_InitStructure.EXTI_LineCmd = ENABLE; //使能中断线
EXTI_Init(&EXTI_InitStructure); //初始
PWR_PVDLevelConfig(PWR_PVDLevel_2V8);//设定监控阀值2.8V
PWR_PVDCmd(ENABLE);//使能PVD
}
extern float Length;
u16 DATA_Buffer[2];
void PVD_IRQHandler(void)
{
EXTI_ClearITPendingBit(EXTI_Line16);//清中断
DATA_Buffer[0]=(u16)(Length);
DATA_Buffer[1]=(u16)((Length - DATA_Buffer[0])*1000);
//存放断电前的数据
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE);//使能PWR和BKP外设时钟
PWR_BackupAccessCmd(ENABLE);//使能后备寄存器访问
BKP_WriteBackupRegister(BKP_DR2, DATA_Buffer[0]);
BKP_WriteBackupRegister(BKP_DR3, DATA_Buffer[1]);
}
/////////////////////////////////////////////////////////////////////////////////////////
复位备份寄存器中的数据不会丢失,但是一旦掉电数据就丢失了,我查到的原因说掉电后PVD会产生两个中断,电容供电前会将备份寄存器复位,请问该怎么解决?
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>