目前我如图配置只能实现进入一次时钟中断,如何配置ertc_alarm_value_set(3)这个函数实现每5分钟进一次ERTC闹钟中断,有没有大神指点一下。
1、
static void ERTC_AlarmConfig(void)
{
EXTI_InitType EXTI_InitStructure;
// ERTC_AlarmType ERTC_AlarmStructure;
NVIC_InitType NVIC_InitStructure;
/* EXTI configuration */
EXTI_ClearIntPendingBit(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_LineEnable = ENABLE;
EXTI_Init(&EXTI_InitStructure);
/* Enable the ERTC Alarm Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = ERTC_IRQn;//ERTCAlarm_IRQn
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
/* Set the alarm A Masks */
ERTC_AlarmStructure.ERTC_AlarmMask = ERTC_AlarmMask_DateWeek | ERTC_AlarmMask_Hours | ERTC_AlarmMask_Seconds;
ERTC_AlarmStructure.ERTC_AlarmDateWeekSel = ERTC_AlarmDateWeekSel_Date;
ERTC_AlarmStructure.ERTC_AlarmDateWeek = ERTC_Week_MON;
ERTC_AlarmStructure.ERTC_AlarmTime.ERTC_Hours = 0X0;
ERTC_AlarmStructure.ERTC_AlarmTime.ERTC_Minutes = 0X5;
ERTC_AlarmStructure.ERTC_AlarmTime.ERTC_Seconds = 0X0;
ERTC_SetAlarmValue(ERTC_Format_BCD, ERTC_AlA, &ERTC_AlarmStructure);
/* Enable alarm A interrupt */
ERTC_INTConfig(ERTC_INT_ALA, ENABLE);
/* Enable the alarmA */
ERTC_AlarmCmd(ERTC_AlA, ENABLE);
}
2、static void ERTC_Config(void)
{
/* Enable the PWR clock */
// RCC_APB1PeriphClockCmd(RCC_APB1PERIPH_PWR, ENABLE);
/* Allow access to ERTC */
PWR_BackupAccessCtrl(ENABLE);
/* Reset ERTC Domain */
RCC_BackupResetCmd(ENABLE);
RCC_BackupResetCmd(DISABLE);
/* Enable the LSE OSC */
// RCC_HSEConfig(RCC_HSE_ENABLE); //启用HSE
RCC_LSICmd(ENABLE); //启用LSI
/* Wait till LSE is ready */
while(RCC_GetFlagStatus(RCC_FLAG_LSISTBL) == RESET)
{
}
/* Select the ERTC Clock Source */
RCC_ERTCCLKConfig(RCC_ERTCCLKSelection_LSI);
/* Enable the ERTC Clock */
RCC_ERTCCLKCmd(ENABLE);
/* Deinitializes the ERTC registers */
ERTC_Reset();
/* Wait for ERTC APB registers synchronisation */
ERTC_WaitForSynchro();
/* Configure the ERTC data register and ERTC prescaler */
/* ck_spre(1Hz) = ERTCCLK(LSI) /(AsynchPrediv + 1)*(SynchPrediv + 1)*/
ERTC_InitStructure.ERTC_AsynchPrediv = 0x7F;
ERTC_InitStructure.ERTC_SynchPrediv = 0x13F;//0xFF;
ERTC_InitStructure.ERTC_HourFormat = ERTC_HourFormat_24;
ERTC_Init(&ERTC_InitStructure);
/* Set the time to 00h 00mn 00s AM */
ERTC_TimeStruct.ERTC_AMPM = ERTC_H12_AM;
ERTC_TimeStruct.ERTC_Hours = 0;
ERTC_TimeStruct.ERTC_Minutes = 0;
ERTC_TimeStruct.ERTC_Seconds = 0;
ERTC_SetTimeValue(ERTC_Format_BCD, &ERTC_TimeStruct);
}
3、
int main(void)
{
__IO uint32_t systick_index = 0;
System_Init(); //硬件初始化
Init_Function(); //功能部件初始化
init_sucess_flag = 1;
// bsp_StartAutoTimer(3, 30000); //50ms定时器
//初始化看门狗,时间3S左右
//stop
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
RCC_APB1PeriphClockCmd(RCC_APB1PERIPH_PWR, ENABLE);
ERTC_Config();
ERTC_AlarmConfig();
EXTI9_Config();
EXTI15_Config();
//进入主程序循环体
// _IWDG_Init();
while (1)
{
//UpdateJudge(); //判断是否有更新程序
bsp_Idle(); //调用MODS_Poll()
Modbus_Data_P();
RCC_GetClocksFreq(&get_rcc_clock);
PLC_Function();
LED_RUN_Function();
// Sys_Reboot_Count_Function();
ConfigModuleNoBlock();
// ertc_alarm_value_set(3);
len = rbCanRead(&rb_t_usart1_read);//读取数据
if(len > 0)
{
memset(usart1_read_buff_copy, 0, rb_t_usart1_read_buff_len);
rbRead(&rb_t_usart1_read, usart1_read_buff_copy, len);//!!!!!!!!!!!!!!!!!!!!!!!!!!
if(ConfigConnectDispose != NULL)
{
ConfigConnectDispose((char*)usart1_read_buff_copy, len);
}
}
//
if(Stop_Flag == 0 && SYS_start == 0)
{
// systick_index = SysTick->CTRL;
// systick_index &= ~((uint32_t)0xFFFFFFFE);
// SysTick->CTRL &= (uint32_t)0xFFFFFFFE;
// ertc_alarm_value_set(3);
// ERTC_TimeStruct.ERTC_AMPM = ERTC_H12_AM;
// ERTC_TimeStruct.ERTC_Hours = 0;
// ERTC_TimeStruct.ERTC_Minutes = 0;
// ERTC_TimeStruct.ERTC_Seconds = 0;
// ERTC_SetTimeValue(ERTC_Format_BCD, &ERTC_TimeStruct);
PWR_EnterSTOPMode(PWR_Regulator_LowPower_Extra, PWR_STOPEntry_WFI);
// SysTick->CTRL |= 0x1;
// SysTick->CTRL |= systick_index;
SYSCLKConfig_STOP();
}
}
}
4、
void ertc_alarm_value_set(uint32_t alam_index)
{
// ERTC_InitType ERTC_InitStructure;
ERTC_TimeType ERTC1_TimeStruct;
// ERTC_AlarmType ERTC_AlarmStructure;
// ERTC_TimeType ERTC_TimeStruct;
/* disable the alarm */
// ertc_alarm_enable(ERTC_ALA, FALSE);
ERTC_AlarmCmd(ERTC_AlA, DISABLE);
//ertc_calendar_get(&ertc_time_struct);
ERTC_GetTimeValue(ERTC_Format_BCD, &ERTC1_TimeStruct);
//ertc_alarm_set(ERTC_ALA, ertc_time_struct.day, ertc_time_struct.hour, ertc_time_struct.min, (ertc_time_struct.sec + alam_index)% 60, ertc_time_struct.ampm);
ERTC_AlarmStructure.ERTC_AlarmMask = ERTC_AlarmMask_DateWeek | ERTC_AlarmMask_Hours | ERTC_AlarmMask_Seconds;
ERTC_AlarmStructure.ERTC_AlarmDateWeekSel = ERTC_AlarmDateWeekSel_Date;
// ERTC_AlarmStructure.ERTC_AlarmDateWeek = ERTC_Week_MON;
ERTC_AlarmStructure.ERTC_AlarmTime.ERTC_Hours = ERTC1_TimeStruct.ERTC_Hours;
ERTC_AlarmStructure.ERTC_AlarmTime.ERTC_Minutes = (ERTC1_TimeStruct.ERTC_Minutes+alam_index) % 60;
ERTC_AlarmStructure.ERTC_AlarmTime.ERTC_Seconds = ERTC1_TimeStruct.ERTC_Seconds;
ERTC_AlarmStructure.ERTC_AlarmTime.ERTC_AMPM = ERTC1_TimeStruct.ERTC_AMPM;
ERTC_SetAlarmValue(ERTC_Format_BCD, ERTC_AlA, &ERTC_AlarmStructure);
ERTC_AlarmCmd(ERTC_AlA, ENABLE);
/* disable the alarm */
ERTC_AlarmCmd(ERTC_AlA, ENABLE);
}
void SYSCLKConfig_STOP(void)
{
RCC_HSEConfig(RCC_HSE_ENABLE);
HSEStartUpStatus = RCC_WaitForHSEStable();
if(HSEStartUpStatus == SUCCESS)
{
RCC_PLLCmd(ENABLE);
while(RCC_GetFlagStatus(RCC_FLAG_PLLSTBL) == RESET)
{
}
RCC_SYSCLKConfig(RCC_SYSCLKSelction_PLL);
while(RCC_GetSYSCLKSelction() != 0x08)
{
}
}
}
5、
oid ERTC_IRQHandler(void)
{
if(ERTC_GetINTStatus(ERTC_INT_ALA) != RESET)
{
/* Clear ERTC AlarmA Flags */
Stop_Flag = 1;
Report_5min_flag = 1;
ERTC_ClearINTPendingBINT(ERTC_INT_ALA);
}
/* Clear the EXTI line 17 */
EXTI_ClearIntPendingBit(EXTI_Line17);
} |