STM32F030使用RTC周期性唤醒STOP模式

首先,F030与F072的RTC唤醒功能是不一样的,在相关定义文件stm32f0xx_exti.h中有如下定义:

#define EXTI_Line17      ((uint32_t)0x00020000)  /*!< Internal interrupt line 17 
                                                      Connected to the RTC Alarm 
                                                      event */

#define EXTI_Line20      ((uint32_t)0x00100000)   /*!< Internal interrupt line 20
                                                      Connected to the RTC wakeup
                                                      event, only applicable for 
                                                      STM32F072 devices  */

也就是最好用最正宗的RTC唤醒功能(EXTI_Line20)只能用在F072上,不能用于F030,所以只能使用RTC Alarm( EXTI_Line17) 方式来唤醒RTC。

RTC设置流程如下:

1.初始设置RTC的秒时钟:

    RTC_InitStructure.RTC_AsynchPrediv
    RTC_InitStructure.RTC_SynchPrediv 

计算方法:LSI=40000HZ;

  LSI/(RTC_AsynchPrediv+1)/(RTC_SynchPrediv +1) =1


2.开启RTC中断及NVIC

    /* EXTI configuration */
    EXTI_ClearITPendingBit(EXTI_Line17);
    EXTI_InitStructure.EXTI_Line = EXTI_Line17;
    EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
    EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
    EXTI_InitStructure.EXTI_LineCmd = ENABLE;

    NVIC_InitStruct.NVIC_IRQChannel = RTC_IRQn;
    NVIC_InitStruct.NVIC_IRQChannelPriority = 1;
    NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE;

3.每次进入休眠之前,都要设置闹钟RTC Alarm

    RTC_AlarmStructure.RTC_AlarmTime.RTC_H12     = RTC_H12_AM;
    RTC_AlarmStructure.RTC_AlarmTime.RTC_Hours   = 0x01;
    RTC_AlarmStructure.RTC_AlarmTime.RTC_Minutes = 0x00;
    RTC_AlarmStructure.RTC_AlarmTime.RTC_Seconds = nDelayCNT;//0x05;
    RTC_AlarmStructure.RTC_AlarmDateWeekDay = 0x31;

其中nDelayCNT就是需要达到的唤醒时间长度,单位是秒(s).


至此,就算是把RTC唤醒搞定了 ,当然还有包括其他比如时钟RCC的设置,暂时以官方例程为准。


猜你喜欢

转载自blog.csdn.net/triv2009/article/details/70568547