通过RTC Alarm A进行日期时间定时中断
①EXTI_InitTypeDef //结构体定义
NVIC_InitTypeDef
void EXTI_ClearITPendingBit(uint32_t EXTI_Line); //清除外部中断17
线:EXTI_Line17
void EXTI_Init(EXTI_InitTypeDef* EXTI_InitStruct); //外部中断装载
线:17
模式:中断
触发:上升沿
void NVIC_PriorityGroupConfig(uint32_t NVIC_PriorityGroup); //向量分组
* @arg NVIC_PriorityGroup_0: 0 bits for pre-emption priority
* 4 bits for subpriority
* @arg NVIC_PriorityGroup_1: 1 bits for pre-emption priority
* 3 bits for subpriority
* @arg NVIC_PriorityGroup_2: 2 bits for pre-emption priority
* 2 bits for subpriority
* @arg NVIC_PriorityGroup_3: 3 bits for pre-emption priority
* 1 bits for subpriority
* @arg NVIC_PriorityGroup_4: 4 bits for pre-emption priority
* 0 bits for subpriority
void NVIC_Init(NVIC_InitTypeDef* NVIC_InitStruct); //中断向量初始化
频道:RTC_Alarm_IRQn
②进行中断时间设定和Alarm的开启
RTC_TimeTypeDef //定义一个读,一个写入
RTC_AlarmTypeDef
ErrorStatus RTC_AlarmCmd(uint32_t RTC_Alarm, FunctionalState NewState); //Disable,Alarm A
* @param RTC_Alarm: specifies the alarm to be configured.
* This parameter can be any combination of the following values:
* @arg RTC_Alarm_A: to select Alarm A
* @arg RTC_Alarm_B: to select Alarm B
* @param NewState: new state of the specified alarm.
* This parameter can be: ENABLE or DISABLE.
void RTC_GetTime(uint32_t RTC_Format, RTC_TimeTypeDef* RTC_TimeStruct); //读时间,BIN制式
void RTC_SetAlarm(uint32_t RTC_Format, uint32_t RTC_Alarm, RTC_AlarmTypeDef* RTC_AlarmStruct);
//设定Alarm细节
Format:二进制
Alarm:
* @param RTC_Alarm: specifies the alarm to be configured.
* This parameter can be one of the following values:
* @arg RTC_Alarm_A: to select Alarm A√
* @arg RTC_Alarm_B: to select Alarm B
结构体:
typedef struct
{
RTC_TimeTypeDef RTC_AlarmTime; /*!< Specifies the RTC Alarm Time members. */ //双重结构体,用两个.衔接
typedef struct
{
uint8_t RTC_Hours;
uint8_t RTC_Minutes;
uint8_t RTC_Seconds;
uint8_t RTC_H12;
}RTC_TimeTypeDef;
uint32_t RTC_AlarmMask; /*!< Specifies the RTC Alarm Masks. //屏蔽不需要的参数
This parameter can be a value of @ref RTC_AlarmMask_Definitions */
#define RTC_AlarmMask_None ((uint32_t)0x00000000)
#define RTC_AlarmMask_DateWeekDay ((uint32_t)0x80000000)√秒定时
#define RTC_AlarmMask_Hours ((uint32_t)0x00800000)√秒定时
#define RTC_AlarmMask_Minutes ((uint32_t)0x00008000)√秒定时
#define RTC_AlarmMask_Seconds ((uint32_t)0x00000080)
#define RTC_AlarmMask_All ((uint32_t)0x80808080)
uint32_t RTC_AlarmDateWeekDaySel; /*!< Specifies the RTC Alarm is on Date or WeekDay. //用星期表示还是日期
This parameter can be a value of @ref RTC_AlarmDateWeekDay_Definitions */
#define RTC_AlarmDateWeekDaySel_Date ((uint32_t)0x00000000)√
#define RTC_AlarmDateWeekDaySel_WeekDay ((uint32_t)0x40000000)
uint8_t RTC_AlarmDateWeekDay; /*!< Specifies the RTC Alarm Date/WeekDay.
If the Alarm Date is selected, this parameter
must be set to a value in the 1-31 range.
If the Alarm WeekDay is selected, this
parameter can be a value of @ref RTC_WeekDay_Definitions */
#define RTC_Weekday_Monday ((uint8_t)0x01)
#define RTC_Weekday_Tuesday ((uint8_t)0x02)
#define RTC_Weekday_Wednesday ((uint8_t)0x03)
#define RTC_Weekday_Thursday ((uint8_t)0x04)
#define RTC_Weekday_Friday ((uint8_t)0x05)
#define RTC_Weekday_Saturday ((uint8_t)0x06)
#define RTC_Weekday_Sunday ((uint8_t)0x07)
}RTC_AlarmTypeDef;
void RTC_ITConfig(uint32_t RTC_IT, FunctionalState NewState); //注册RTC中断
* @arg RTC_IT_TS: Time Stamp interrupt mask
* @arg RTC_IT_WUT: WakeUp Timer interrupt mask
* @arg RTC_IT_ALRB: Alarm B interrupt mask
* @arg RTC_IT_ALRA: Alarm A interrupt mask√
* @arg RTC_IT_TAMP: Tamper event interrupt mask
ErrorStatus RTC_AlarmCmd(uint32_t RTC_Alarm, FunctionalState NewState); //Alarm开启
* @param RTC_Alarm: specifies the alarm to be configured.
* This parameter can be any combination of the following values:
* @arg RTC_Alarm_A: to select Alarm A√
* @arg RTC_Alarm_B: to select Alarm B
* @param NewState: new state of the specified alarm.
* This parameter can be: ENABLE√ or DISABLE.
* @retval An ErrorStatus enumeration value:
* - SUCCESS: RTC Alarm is enabled/disabled
* - ERROR: RTC Alarm is not enabled/disabled
void RTC_ClearFlag(uint32_t RTC_FLAG); //清除RTC标记
* @param RTC_FLAG: specifies the RTC flag to clear.
* This parameter can be any combination of the following values:
* @arg RTC_FLAG_TAMP1F: Tamper 1 event flag
* @arg RTC_FLAG_TSOVF: Time Stamp Overflow flag
* @arg RTC_FLAG_TSF: Time Stamp event flag
* @arg RTC_FLAG_WUTF: WakeUp Timer flag
* @arg RTC_FLAG_ALRBF: Alarm B flag
* @arg RTC_FLAG_ALRAF: Alarm A flag√
* @arg RTC_FLAG_RSF: Registers Synchronized flag
③Alarm A中断服务
void RTC_Alarm_IRQHandler(void)
{
if(RTC_GetITStatus(RTC_IT_ALRA)!=RESET)
{
xxxxxxxx //用户执行代码 EXTI_ClearITPendingBit(EXTI_Line17); //清EXTI_Line17挂起位 RTC_ClearITPendingBit(RTC_IT_ALRA); //清除中断标志
RTC_ClearFlag(RTC_FLAG_ALRAF);
}
}