STM32的备份寄存器测试

1. 研究STM3的备份寄存器,注意,如果要测试这个例程的话,VBAT不能和VDD接一起,必须分开。

2. 理解,备份寄存器可以有VBAT独立供电,也就是外接电池,备份寄存器在VBAT供电情况下,如果发生系统复位(按键复位)和上电复位,备份寄存器的值可以保持。

3. 代码如下:

 1 int main(void)
 2 {
 3 #ifdef DEBUG
 4   debug();
 5 #endif
 6 
 7   /* System Clocks Configuration */
 8   RCC_Configuration();
 9   
10   /* NVIC configuration */
11   NVIC_Configuration();
12 
13   /* GPIO configuration */
14   GPIO_Configuration();
15   
16   /* Enable PWR and BKP clock */
17   RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE);
18 
19   /* Enable write access to Backup domain */
20   PWR_BackupAccessCmd(ENABLE);
21 
22   /* Clear Tamper pin Event(TE) pending flag */
23   BKP_ClearFlag();
24 
25   //首先判断是不是上电复位的
26   if(RCC_GetFlagStatus(RCC_FLAG_PORRST) != RESET)
27   {
28     /* Clear reset flags */
29     RCC_ClearFlag();
30 
31     /* Turn on led connected to GPIO_LED Pin8 */
32     GPIO_SetBits(GPIO_LED, GPIO_Pin_8);
33    
34     /* Check if Backup data registers are programmed */
35     if(CheckBackupReg(0x3211) == 0x00)
36     { /* Backup data registers values are correct */
37 
38       /* Turn on led connected to GPIO_LED Pin6 */
39       GPIO_SetBits(GPIO_LED, GPIO_Pin_6);
40     }
41     else
42     { /* Backup data registers values are not correct or they are not yet
43          programmed (when the first time the program is executed) */
44 
45       /* Write data to Backup data registers */
46       WriteToBackupReg(0x3211);
47 
48       /* Turn on led connected to GPIO_LED Pin7 */
49       GPIO_SetBits(GPIO_LED, GPIO_Pin_7);
50     }
51   }
52 
53   /* Turn on led connected to GPIO_LED Pin9 */
54   GPIO_SetBits(GPIO_LED, GPIO_Pin_9);  
55        
56   while (1)
57   {    
58   }
59 }

4. 测试,第一次上电,亮灯LED7,LED8,LED9,然后VDD断电重新上电,亮灯LED6,LED8,LED9,然后按复位按键,亮灯LED9(代码只检查是不是上电复位)

5. 程序比较简单,主要是备份寄存器的作用。

转载于:https://www.cnblogs.com/429512065qhq/p/8082717.html

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值