本文整理汇总了C++中RTC_WaitForSynchro函数的典型用法代码示例。如果您正苦于以下问题:C++ RTC_WaitForSynchro函数的具体用法?C++ RTC_WaitForSynchro怎么用?C++ RTC_WaitForSynchro使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了RTC_WaitForSynchro函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: StandbyRTCMode_Measure
/**
* @brief This function configures the system to enter Standby mode with RTC
* clocked by LSI for current consumption measurement purpose.
* STANDBY Mode with RTC clocked by LSI
* ========================================
* - RTC Clocked by LSI
* - IWDG OFF
* - Automatic Wakeup using RTC
* @param None
* @retval None
*/
void StandbyRTCMode_Measure(void)
{
RTC_InitTypeDef RTC_InitStructure;
RTC_AlarmTypeDef RTC_AlarmStructure;
RTC_TimeTypeDef RTC_TimeStructure;
/* Allow access to RTC */
PWR_BackupAccessCmd(ENABLE);
/* The RTC Clock may varies due to LSI frequency dispersion. */
/* Enable the LSI OSC */
RCC_LSICmd(ENABLE);
/* Wait till LSI is ready */
while(RCC_GetFlagStatus(RCC_FLAG_LSIRDY) == RESET)
{
}
/* Select the RTC Clock Source */
RCC_RTCCLKConfig(RCC_RTCCLKSource_LSI);
/* Enable the RTC Clock */
RCC_RTCCLKCmd(ENABLE);
/* Wait for RTC APB registers synchronisation */
RTC_WaitForSynchro();
RTC_InitStructure.RTC_HourFormat = RTC_HourFormat_24;
RTC_InitStructure.RTC_AsynchPrediv = 0x7F;
RTC_InitStructure.RTC_SynchPrediv = 0x0138;
RTC_Init(&RTC_InitStructure);
/* Set the alarm X+5s */
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 = 0x08;
RTC_AlarmStructure.RTC_AlarmDateWeekDay = 0x31;
RTC_AlarmStructure.RTC_AlarmDateWeekDaySel = RTC_AlarmDateWeekDaySel_Date;
RTC_AlarmStructure.RTC_AlarmMask = RTC_AlarmMask_DateWeekDay;
RTC_SetAlarm(RTC_Format_BCD, RTC_Alarm_A, &RTC_AlarmStructure);
/* Enable RTC Alarm A Interrupt */
RTC_ITConfig(RTC_IT_ALRA, ENABLE);
/* Enable the alarm */
RTC_AlarmCmd(RTC_Alarm_A, ENABLE);
/* Set the time to 01h 00mn 00s AM */
RTC_TimeStructure.RTC_H12 = RTC_H12_AM;
RTC_TimeStructure.RTC_Hours = 0x01;
RTC_TimeStructure.RTC_Minutes = 0x00;
RTC_TimeStructure.RTC_Seconds = 0x00;
RTC_SetTime(RTC_Format_BCD, &RTC_TimeStructure);
/* Clear Wakeup flag */
PWR_ClearFlag(PWR_FLAG_WU);
RTC_ClearFlag(RTC_FLAG_ALRAF);
/* Request to enter STANDBY mode (Wake Up flag is cleared in PWR_EnterSTANDBYMode function) */
PWR_EnterSTANDBYMode();
/* Infinite loop */
while (1)
{
}
}
示例2: rtc_init_counter_mode
void rtc_init_counter_mode() {
NVIC_InitTypeDef NVIC_InitStructure;
EXTI_InitTypeDef EXTI_InitStructure;
RTC_InitTypeDef RTC_InitStructure;
/* Enable the PWR clock */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
/* Allow access to RTC */
PWR_RTCAccessCmd(ENABLE);
/* Reset RTC Domain */
RCC_RTCResetCmd(ENABLE);
RCC_RTCResetCmd(DISABLE);
/* Enable the LSE OSC */
RCC_LSEConfig(RCC_LSE_ON );
/* Wait till LSE is ready */
while (RCC_GetFlagStatus(RCC_FLAG_LSERDY ) == RESET) {
}
/* Select the RTC Clock Source */
RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE );
/* Set the RTC time base to 1s */
RTC_InitStructure.RTC_HourFormat = RTC_HourFormat_24;
RTC_InitStructure.RTC_AsynchPrediv = 0x7F;
RTC_InitStructure.RTC_SynchPrediv = 0x00FF;
RTC_Init(&RTC_InitStructure);
/* Enable the RTC Clock */
RCC_RTCCLKCmd(ENABLE);
/* Wait for RTC APB registers synchronization */
RTC_WaitForSynchro();
/* EXTI configuration *******************************************************/
EXTI_ClearITPendingBit(EXTI_Line20 );
EXTI_InitStructure.EXTI_Line = EXTI_Line20;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
/* Enable the RTC Wakeup Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = RTC_WKUP_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
/* Configure the RTC WakeUp Clock source: CK_SPRE (1Hz) */
RTC_WakeUpClockConfig(RTC_WakeUpClock_CK_SPRE_16bits );
RTC_SetWakeUpCounter(0x0);
/* Enable the RTC Wakeup Interrupt */
RTC_ITConfig(RTC_IT_WUT, ENABLE);
rtc_disable_interrupt();
/* Enable Wakeup Counter */
RTC_WakeUpCmd(ENABLE);
}
示例3: RTC_Config
/**
* @brief Configure the RTC peripheral by selecting the clock source.
* @param None
* @retval None
*/
void RTC_Config(void)
{
/* Enable the PWR clock */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
/* Allow access to RTC */
PWR_BackupAccessCmd(ENABLE);
#if defined (RTC_CLOCK_SOURCE_LSI) /* LSI used as RTC source clock*/
/* The RTC Clock may varies due to LSI frequency dispersion. */
/* Enable the LSI OSC */
RCC_LSICmd(ENABLE);
/* Wait till LSI is ready */
while(RCC_GetFlagStatus(RCC_FLAG_LSIRDY) == RESET)
{
}
/* Select the RTC Clock Source */
RCC_RTCCLKConfig(RCC_RTCCLKSource_LSI);
SynchPrediv = 0xFF;
AsynchPrediv = 0x7F;
#elif defined (RTC_CLOCK_SOURCE_LSE) /* LSE used as RTC source clock */
/* Enable the LSE OSC */
RCC_LSEConfig(RCC_LSE_ON);
/* Wait till LSE is ready */
while(RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET)
{
}
/* Select the RTC Clock Source */
RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);
SynchPrediv = 0xFF;
AsynchPrediv = 0x7F;
#else
#error Please select the RTC Clock source inside the main.c file
#endif /* RTC_CLOCK_SOURCE_LSI */
/* Enable the RTC Clock */
RCC_RTCCLKCmd(ENABLE);
/* Wait for RTC APB registers synchronisation */
RTC_WaitForSynchro();
/* Write to the first RTC Backup Data Register */
RTC_WriteBackupRegister(RTC_BKP_DR0, FIRST_DATA);
/* Display the new RCC BDCR and RTC TAFCR Registers */
LCD_UsrLog ("RTC Reconfig \n");
LCD_UsrLog ("RCC BDCR = 0x%x\n", RCC->BDCR);
LCD_UsrLog ("RTC TAFCR = 0x%x\n", RTC->TAFCR);
/* Set the Time */
RTC_TimeStructure.RTC_Hours = 0x08;
RTC_TimeStructure.RTC_Minutes = 0x00;
RTC_TimeStructure.RTC_Seconds = 0x00;
/* Set the Date */
RTC_DateStructure.RTC_Month = RTC_Month_March;
RTC_DateStructure.RTC_Date = 0x18;
RTC_DateStructure.RTC_Year = 0x11;
RTC_DateStructure.RTC_WeekDay = RTC_Weekday_Friday;
/* Calendar Configuration */
RTC_InitStructure.RTC_AsynchPrediv = AsynchPrediv;
RTC_InitStructure.RTC_SynchPrediv = SynchPrediv;
RTC_InitStructure.RTC_HourFormat = RTC_HourFormat_24;
RTC_Init(&RTC_InitStructure);
/* Set Current Time and Date */
RTC_SetTime(RTC_Format_BCD, &RTC_TimeStructure);
RTC_SetDate(RTC_Format_BCD, &RTC_DateStructure);
/* Configure the RTC Wakeup Clock source and Counter (Wakeup event each 1 second) */
RTC_WakeUpClockConfig(RTC_WakeUpClock_RTCCLK_Div16);
RTC_SetWakeUpCounter(0x7FF);
/* Enable the Wakeup Interrupt */
RTC_ITConfig(RTC_IT_WUT, ENABLE);
/* Enable Wakeup Counter */
RTC_WakeUpCmd(ENABLE);
/* Backup SRAM ***************************************************************/
/* Enable BKPRAM Clock */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_BKPSRAM, ENABLE);
/* Write to Backup SRAM with 32-Bit Data */
for (i = 0x0; i < 0x1000; i += 4)
{
//.........这里部分代码省略.........
示例4: StopMode_Measure
/**
* @brief This function configures the system to enter Stop mode with RTC
* clocked by LSI for current consumption measurement purpose.
* STOP Mode with RTC clocked by LSI
* =====================================
* - RTC Clocked by LSI
* - Regulator in LP mode
* - HSI, HSE OFF and LSI OFF if not used as RTC Clock source
* - No IWDG
* - FLASH in deep power down mode
* - Automatic Wakeup using RTC clocked by LSI (~5s)
* @param None
* @retval None
*/
void StopMode_Measure(void)
{
__IO uint32_t index = 0;
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
EXTI_InitTypeDef EXTI_InitStructure;
/* Allow access to RTC */
PWR_BackupAccessCmd(ENABLE);
/* The RTC Clock may varies due to LSI frequency dispersion. */
/* Enable the LSI OSC */
RCC_LSICmd(ENABLE);
/* Wait till LSI is ready */
while(RCC_GetFlagStatus(RCC_FLAG_LSIRDY) == RESET)
{
}
/* Select the RTC Clock Source */
RCC_RTCCLKConfig(RCC_RTCCLKSource_LSI);
/* Enable the RTC Clock */
RCC_RTCCLKCmd(ENABLE);
/* Wait for RTC APB registers synchronisation */
RTC_WaitForSynchro();
/* Configure all GPIO as analog to reduce current consumption on non used IOs */
/* Enable GPIOs clock */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA | RCC_AHBPeriph_GPIOB | RCC_AHBPeriph_GPIOC |
RCC_AHBPeriph_GPIOD | RCC_AHBPeriph_GPIOF , ENABLE);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
GPIO_Init(GPIOC, &GPIO_InitStructure);
GPIO_Init(GPIOD, &GPIO_InitStructure);
GPIO_Init(GPIOF, &GPIO_InitStructure);
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_Init(GPIOB, &GPIO_InitStructure);
/* Disable GPIOs clock */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA |RCC_AHBPeriph_GPIOB | RCC_AHBPeriph_GPIOC |
RCC_AHBPeriph_GPIOD | RCC_AHBPeriph_GPIOF, DISABLE);
/* Configure EXTI Line20 corresponding to the RTC Wakeup interrupt */
EXTI_ClearITPendingBit(EXTI_Line20);
EXTI_InitStructure.EXTI_Line = EXTI_Line20;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
/* NVIC configuration */
NVIC_InitStructure.NVIC_IRQChannel = RTC_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
/* RTC Wakeup Interrupt Generation: Clock Source: RTCCLK_Div16, Wakeup Time Base: ~5s
RTC Clock Source LSI ~32KHz
Wakeup Time Base = (16 / (LSI)) * WakeUpCounter
*/
RTC_WakeUpClockConfig(RTC_WakeUpClock_RTCCLK_Div16);
RTC_SetWakeUpCounter(0x2800-1);
/* Enable the Wakeup Interrupt */
RTC_ITConfig(RTC_IT_WUT, ENABLE);
/* Enable Wakeup Counter */
RTC_WakeUpCmd(ENABLE);
/* Enter Stop Mode */
PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI);
/* Initialize LED4 */
STM_EVAL_LEDInit(LED4);
/* Infinite loop */
while (1)
{
/* Toggle The LED4 */
STM_EVAL_LEDToggle(LED4);
//.........这里部分代码省略.........
示例5: StopMode_Measure
/**
* @brief This function configures the system to enter Stop mode with RTC
* clocked by LSE or LSI for current consumption measurement purpose.
* STOP Mode with RTC clocked by LSE/LSI
* =====================================
* - RTC Clocked by LSE or LSI
* - Regulator in LP mode
* - HSI, HSE OFF and LSI OFF if not used as RTC Clock source
* - No IWDG
* - FLASH in deep power down mode
* - Automatic Wakeup using RTC clocked by LSE/LSI (~20s)
* @param None
* @retval None
*/
void StopMode_Measure(void)
{
__IO uint32_t index = 0;
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
EXTI_InitTypeDef EXTI_InitStructure;
/* Allow access to RTC */
PWR_BackupAccessCmd(ENABLE);
#if defined (RTC_CLOCK_SOURCE_LSI) /* LSI used as RTC source clock*/
/* The RTC Clock may varies due to LSI frequency dispersion. */
/* Enable the LSI OSC */
RCC_LSICmd(ENABLE);
/* Wait till LSI is ready */
while(RCC_GetFlagStatus(RCC_FLAG_LSIRDY) == RESET)
{
}
/* Select the RTC Clock Source */
RCC_RTCCLKConfig(RCC_RTCCLKSource_LSI);
#elif defined (RTC_CLOCK_SOURCE_LSE) /* LSE used as RTC source clock */
/* Enable the LSE OSC */
RCC_LSEConfig(RCC_LSE_ON);
/* Wait till LSE is ready */
while(RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET)
{
}
/* Select the RTC Clock Source */
RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);
#else
#error Please select the RTC Clock source inside the main.c file
#endif /* RTC_CLOCK_SOURCE_LSI */
/* Enable the RTC Clock */
RCC_RTCCLKCmd(ENABLE);
/* Wait for RTC APB registers synchronisation */
RTC_WaitForSynchro();
/* Configure all GPIO as analog to reduce current consumption on non used IOs */
/* Enable GPIOs clock */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOB | RCC_AHB1Periph_GPIOC |
RCC_AHB1Periph_GPIOD | RCC_AHB1Periph_GPIOE | RCC_AHB1Periph_GPIOF |
RCC_AHB1Periph_GPIOG | RCC_AHB1Periph_GPIOH | RCC_AHB1Periph_GPIOI, ENABLE);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
GPIO_Init(GPIOC, &GPIO_InitStructure);
GPIO_Init(GPIOD, &GPIO_InitStructure);
GPIO_Init(GPIOE, &GPIO_InitStructure);
GPIO_Init(GPIOF, &GPIO_InitStructure);
GPIO_Init(GPIOG, &GPIO_InitStructure);
GPIO_Init(GPIOH, &GPIO_InitStructure);
GPIO_Init(GPIOI, &GPIO_InitStructure);
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_Init(GPIOB, &GPIO_InitStructure);
/* Disable GPIOs clock */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOB | RCC_AHB1Periph_GPIOC |
RCC_AHB1Periph_GPIOD | RCC_AHB1Periph_GPIOE | RCC_AHB1Periph_GPIOF |
RCC_AHB1Periph_GPIOG | RCC_AHB1Periph_GPIOH | RCC_AHB1Periph_GPIOI, DISABLE);
/* EXTI configuration *******************************************************/
EXTI_ClearITPendingBit(EXTI_Line22);
EXTI_InitStructure.EXTI_Line = EXTI_Line22;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
/* Enable the RTC Wakeup Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = RTC_WKUP_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
//.........这里部分代码省略.........
示例6: portInitClock
/*
* This tick module runs with or without periodic tick. If periodic
* tick is used, RTC wakeup counter is used to generate it.
* In tickless mode, SysTick is used to generate tick and RTC is
* used for wakeup from tickless sleep.
*/
void portInitClock(void)
{
#if POSCFG_FEATURE_TICKLESS != 0
/*
* Initialize Systick timer.
*/
SysTick_Config(SystemCoreClock / HZ);
NVIC_SetPriority(SysTick_IRQn, PORT_SYSTICK_PRI);
#endif
/*
* Initialize RTC.
*/
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
PWR_BackupAccessCmd(ENABLE);
RCC_LSEConfig(RCC_LSE_ON);
while (RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET) {
}
RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);
RCC_RTCCLKCmd(ENABLE);
/*
* RTC_WaitForSynchro has a little bit too small timeout.
* If it return error, just try again (as we don't have any other
* alternatives than working clock).
*/
RTC_BypassShadowCmd(DISABLE);
while (RTC_WaitForSynchro() == ERROR) {
}
RTC_InitTypeDef RTC_InitStructure;
/*
* RTC ticks every sec. Asynch/Synchr dividers
* are set so that we have 1024 resolution in subseconds.
*/
RTC_InitStructure.RTC_AsynchPrediv = 0x1f;
RTC_InitStructure.RTC_SynchPrediv = 0x3ff;
RTC_InitStructure.RTC_HourFormat = RTC_HourFormat_24;
RTC_Init(&RTC_InitStructure);
RTC_TimeTypeDef time;
RTC_DateTypeDef date;
time.RTC_H12 = 0;
time.RTC_Hours = 0;
time.RTC_Minutes = 0;
time.RTC_Seconds = 0;
date.RTC_Date = 1;
date.RTC_Month = 1;
date.RTC_Year = 0;
date.RTC_WeekDay = RTC_Weekday_Saturday; // 1.1.2000: saturday
RTC_SetTime(RTC_Format_BIN, &time);
RTC_SetDate(RTC_Format_BIN, &date);
RTC_BypassShadowCmd(ENABLE);
/*
* Configure Wakup interrupt
*/
EXTI_InitTypeDef EXTI_InitStructure;
EXTI_InitStructure.EXTI_Line = EXTI_Line22;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
NVIC_SetPriority(RTC_WKUP_IRQn, PORT_SYSTICK_PRI);
RTC_WakeUpCmd(DISABLE);
#if POSCFG_FEATURE_TICKLESS == 0
RTC_WakeUpClockConfig(RTC_WakeUpClock_RTCCLK_Div2);
RTC_SetWakeUpCounter(16384 / HZ);
EXTI_ClearITPendingBit(EXTI_Line22);
RTC_ITConfig(RTC_IT_WUT, ENABLE);
RTC_ClearITPendingBit(RTC_IT_WUT);
RTC_ClearFlag(RTC_FLAG_WUTF);
NVIC_EnableIRQ(RTC_WKUP_IRQn);
RTC_WakeUpCmd(ENABLE);
#endif
//.........这里部分代码省略.........
示例7: RTC_Configuration
/*******************************************************************************
* Function Name : RTC_Configuration
* Description : 来重新配置RTC和BKP,仅在检测到后备寄存器数据丢失时使用
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void RTC_Configuration(void)
{
//启用PWR和BKP的时钟(from APB1)
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE);
//后备域解锁
PWR_BackupAccessCmd(ENABLE);
//备份寄存器模块复位
BKP_DeInit();
//外部32.768K其哟偶那个
RCC_LSEConfig(RCC_LSE_ON);
//等待稳定
while (RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET);
// Lcd_WriteString(10,0,0,Red,"00");
//RTC时钟源配置成LSE(外部32.768K)
RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);
//RTC开启
RCC_RTCCLKCmd(ENABLE);
//开启后需要等待APB1时钟与RTC时钟同步,才能读写寄存器
RTC_WaitForSynchro();
//读写寄存器前,要确定上一个操作已经结束
RTC_WaitForLastTask();
//使能秒中断
RTC_ITConfig(RTC_IT_SEC, ENABLE);
//等待写入完成
RTC_WaitForLastTask();
//设置RTC分频器,使RTC时钟为1Hz
//RTC period = RTCCLK/RTC_PR = (32.768 KHz)/(32767+1)
RTC_SetPrescaler(32767);
//等待寄存器写入完成
RTC_WaitForLastTask();
time_now.tm_year = 2009;
time_now.tm_mon = 7;
time_now.tm_mday = 31;
time_now.tm_hour = 13;
time_now.tm_min = 11;
time_now.tm_sec = 00;
Time_SetCalendarTime(time_now);
return;
}
示例8: RTC_Configuration
/*******************************************************************************
* Function Name : RTC_Configuration
* Description : COnfiguration of RTC Registers, Selection and Enabling of
* RTC clock
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void RTC_Configuration()
{
u16 u16_WaitForOscSource;
/*Allow access to Backup Registers*/
PWR_BackupAccessCmd(ENABLE);
if(BKP_ReadBackupRegister(BKP_DR1)==CONFIGURATION_RESET)
{
/*Enables the clock to Backup and power interface peripherals */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_BKP | RCC_APB1Periph_PWR,ENABLE);
/* Backup Domain Reset */
BKP_DeInit();
s_DateStructVar.u8_Month=DEFAULT_MONTH ;
s_DateStructVar.u8_Day=DEFAULT_DAY;
s_DateStructVar.u16_Year=DEFAULT_YEAR;
u16_SummerTimeCorrect = OCTOBER_FLAG_SET;
BKP_WriteBackupRegister(BKP_DR7,u16_SummerTimeCorrect);
BKP_WriteBackupRegister(BKP_DR2,s_DateStructVar.u8_Month);
BKP_WriteBackupRegister(BKP_DR3,s_DateStructVar.u8_Day);
BKP_WriteBackupRegister(BKP_DR4,s_DateStructVar.u16_Year);
BKP_WriteBackupRegister(BKP_DR1, CONFIGURATION_DONE);
u8_TamperNumber=0;
BKP_WriteBackupRegister(BKP_DR5,u8_TamperNumber);
/*Enable 32.768 kHz external oscillator */
RCC_LSEConfig(RCC_LSE_ON);
for(u16_WaitForOscSource=0;u16_WaitForOscSource<5000;u16_WaitForOscSource++)
{
}
RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);
/* RTC Enabled */
RCC_RTCCLKCmd(ENABLE);
RTC_WaitForLastTask();
/*Wait for RTC registers synchronisation */
RTC_WaitForSynchro();
RTC_WaitForLastTask();
/* Setting RTC Interrupts-Seconds interrupt enabled */
/* Enable the RTC Second */
RTC_ITConfig(RTC_IT_SEC , ENABLE);
/* Wait until last write operation on RTC registers has finished */
RTC_WaitForLastTask();
BKP_WriteBackupRegister(BKP_DR6, 1);
/* Set RTC prescaler: set RTC period to 1 sec */
RTC_SetPrescaler(32765); /* RTC period = RTCCLK/RTC_PR = (32.768 KHz)/(32767+1) */
/* Prescaler is set to 32766 instead of 32768 to compensate for
lower as well as higher frequencies*/
/* Wait until last write operation on RTC registers has finished */
RTC_WaitForLastTask();
/* Set default system time to 09 : 24 : 00 */
SetTime(DEFAULT_HOURS,DEFAULT_MINUTES,DEFAULT_SECONDS);
BKP_WriteBackupRegister(BKP_DR1, CONFIGURATION_DONE);
}
else
{
//BKP_WriteBackupRegister(BKP_DR1, CONFIGURATION_RESET);
/* PWR and BKP clocks selection */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE);
for(u16_WaitForOscSource=0;u16_WaitForOscSource<5000;u16_WaitForOscSource++);
/* Wait until last write operation on RTC registers has finished */
RTC_WaitForLastTask();
/* Enable the RTC Second */
RTC_ITConfig(RTC_IT_SEC, ENABLE);
RTC_WaitForLastTask();
}
/* Check if how many days are elapsed in power down/Low Power Mode-
Updates Date that many Times*/
CheckForDaysElapsed();
u8_ClockSource = BKP_ReadBackupRegister(BKP_DR6);
u8_TamperNumber = BKP_ReadBackupRegister(BKP_DR5);
s_DateStructVar.u8_Month = BKP_ReadBackupRegister(BKP_DR2);
s_DateStructVar.u8_Day = BKP_ReadBackupRegister(BKP_DR3);
s_DateStructVar.u16_Year = BKP_ReadBackupRegister(BKP_DR4);
u16_SummerTimeCorrect = BKP_ReadBackupRegister(BKP_DR7);
s_AlarmDateStructVar.u8_Month = BKP_ReadBackupRegister(BKP_DR8);
s_AlarmDateStructVar.u8_Day = BKP_ReadBackupRegister(BKP_DR9);
s_AlarmDateStructVar.u16_Year = BKP_ReadBackupRegister(BKP_DR10);
}
示例9: RTC_Config
/**
* @brief Configures the RTC.
* @param None
* @retval None
*/
static void RTC_Config(void)
{
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
/* Allow access to BKP Domain */
PWR_BackupAccessCmd(ENABLE);
/* Clear Wakeup flag */
PWR_ClearFlag(PWR_FLAG_WU);
/* Check if the StandBy flag is set */
if (PWR_GetFlagStatus(PWR_FLAG_SB) != RESET)
{
/* Clear StandBy flag */
PWR_ClearFlag(PWR_FLAG_SB);
/* Wait for RTC APB registers synchronisation (needed after start-up from Reset)*/
RTC_WaitForSynchro();
/* No need to configure the RTC as the RTC config(clock source, enable,
prescaler,...) are kept after wake-up from STANDBY */
}
else
{
/* RTC Configuration ******************************************************/
/* Reset Backup Domain */
RCC_BackupResetCmd(ENABLE);
RCC_BackupResetCmd(DISABLE);
#if defined (RTC_CLOCK_SOURCE_LSI) /* LSI used as RTC source clock*/
/* The RTC Clock may varies due to LSI frequency dispersion. */
/* Enable the LSI OSC */
RCC_LSICmd(ENABLE);
/* Wait till LSI is ready */
while(RCC_GetFlagStatus(RCC_FLAG_LSIRDY) == RESET)
{
}
/* Select the RTC Clock Source */
RCC_RTCCLKConfig(RCC_RTCCLKSource_LSI);
SynchPrediv = 0xFF;
AsynchPrediv = 0x7F;
#elif defined (RTC_CLOCK_SOURCE_LSE) /* LSE used as RTC source clock */
/* Enable the LSE OSC */
RCC_LSEConfig(RCC_LSE_ON);
/* Wait till LSE is ready */
while(RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET)
{
}
/* Select the RTC Clock Source */
RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);
SynchPrediv = 0xFF;
AsynchPrediv = 0x7F;
#else
#error Please select the RTC Clock source inside the main.c file
#endif /* RTC_CLOCK_SOURCE_LSI */
/* Enable the RTC Clock */
RCC_RTCCLKCmd(ENABLE);
/* Wait for RTC APB registers synchronisation (needed after start-up from Reset)*/
RTC_WaitForSynchro();
/* Set the RTC time base to 1s */
RTC_InitStructure.RTC_HourFormat = RTC_HourFormat_24;
RTC_InitStructure.RTC_AsynchPrediv = 0x7F;
RTC_InitStructure.RTC_SynchPrediv = 0x00FF;
if (RTC_Init(&RTC_InitStructure) == ERROR)
{
/* Turn on LED2 */
STM_EVAL_LEDOn(LED2);
/* User can add here some code to deal with this error */
while(1);
}
/* Set the time to 01h 00mn 00s AM */
RTC_TimeStructure.RTC_H12 = RTC_H12_AM;
RTC_TimeStructure.RTC_Hours = 0x01;
RTC_TimeStructure.RTC_Minutes = 0x00;
RTC_TimeStructure.RTC_Seconds = 0x00;
if(RTC_SetTime(RTC_Format_BCD, &RTC_TimeStructure) == ERROR)
{
/* Turn on LED2 */
STM_EVAL_LEDOn(LED2);
/* User can add here some code to deal with this error */
//.........这里部分代码省略.........
示例10: initRtc
// AN2821: Clock/calendar implementation on the STM32F10xxx microcontroller RTC
// http://www.st.com/web/en/resource/technical/document/application_note/CD00207941.pdf
void initRtc() {
RCC_APB1PeriphClockCmd(RCC_APB1Periph_BKP|RCC_APB1Periph_PWR, ENABLE);
PWR_BackupAccessCmd(ENABLE);
#if defined(CLK_SRC_EXT)
RCC_LSEConfig(RCC_LSE_ON);
for (uint16_t i = 0; i < 1<<15; i++) {
if (RCC_GetFlagStatus(RCC_FLAG_LSERDY) == SET) {
trace_printf("LSE clock became ready at iteration %d.\n", i);
break;
}
}
RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);
RTC_WaitForLastTask();
#elif defined(CLK_SRC_INT)
RCC_LSICmd(ENABLE);
for (uint16_t i = 0; i < 1<<15; i++) {
if (RCC_GetFlagStatus(RCC_FLAG_LSIRDY) == SET) {
trace_printf("LSI clock became ready at iteration %d.\n", i);
break;
}
}
RCC_RTCCLKConfig(RCC_RTCCLKSource_LSI);
RTC_WaitForLastTask();
#endif
RCC_RTCCLKCmd(ENABLE);
RTC_WaitForSynchro();
RTC_WaitForLastTask();
// This must come after WaitForSynchro().
#if defined(CLK_SRC_EXT)
RTC_SetPrescaler(32768); // Watch crystal.
RTC_WaitForLastTask();
#elif defined(CLK_SRC_INT)
// RM0041, page 74: "The clock frequency is around 40kHz."
RTC_SetPrescaler(40500);
RTC_WaitForLastTask();
#endif
RTC_ClearITPendingBit(RTC_IT_SEC);
RTC_ITConfig(RTC_IT_ALR|RTC_IT_OW, DISABLE);
RTC_ITConfig(RTC_IT_SEC, ENABLE);
RTC_WaitForLastTask();
PWR_BackupAccessCmd(DISABLE);
NVIC_InitTypeDef NVIC_InitStructure = {
.NVIC_IRQChannel = RTC_IRQn,
.NVIC_IRQChannelPreemptionPriority = 1,
.NVIC_IRQChannelSubPriority = 2,
.NVIC_IRQChannelCmd = ENABLE,
};
NVIC_Init(&NVIC_InitStructure);
}
void initTimer() {
// TIM3 clock enable
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2 | RCC_APB1Periph_TIM3, ENABLE);
// Enable both pins as alternate function.
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Pin = GRID_PIN;
GPIO_Init(GRID_PORT, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = BUZ_PIN;
GPIO_Init(BUZ_PORT, &GPIO_InitStructure);
// Time base configuration;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
// Grid PWM is on PA0 (D11), this is timer 2 channel 1.
// 72MHz system clock / 1800 / 80 = 500Hz
TIM_TimeBaseStructure.TIM_Period = 80;
TIM_TimeBaseStructure.TIM_Prescaler = 1800;
TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
gGridOc.TIM_OCMode = TIM_OCMode_PWM1;
gGridOc.TIM_OCPolarity = TIM_OCPolarity_High;
gGridOc.TIM_OutputState = TIM_OutputState_Enable;
gGridOc.TIM_Pulse = 40; // 40 of period 80 = 50% duty
TIM_OC1Init(TIM2, &gGridOc);
TIM_OC1PreloadConfig(TIM2, TIM_OCPreload_Enable);
TIM_ARRPreloadConfig(TIM2, ENABLE); // ARR = Auto Reload Register
TIM_Cmd(TIM2, ENABLE);
// Buzzer PWM is on PB0 (D3), this is timer 3 channel 3.
// 72MHz system clock / 1800 / 67 = ~600 Hz.
TIM_TimeBaseStructure.TIM_Period = 67;
TIM_TimeBaseStructure.TIM_Prescaler = 1800;
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
gBuzOc.TIM_OCMode = TIM_OCMode_PWM1;
gBuzOc.TIM_OCPolarity = TIM_OCPolarity_High;
gBuzOc.TIM_OutputState = TIM_OutputState_Enable;
gBuzOc.TIM_Pulse = 30;
TIM_OC3Init(TIM3, &gBuzOc);
//.........这里部分代码省略.........
示例11: main
/**
* @brief Main program
* @param None
* @retval None
*/
int main(void)
{
/*!< At this stage the microcontroller clock setting is already configured,
this is done through SystemInit() function which is called from startup
files (startup_stm32f40xx.s/startup_stm32f427x.s) before to branch to
application main.
To reconfigure the default setting of SystemInit() function, refer to
system_stm32f4xx.c file
*/
/* Configure the external interrupt "WAKEUP" and "TAMPER" buttons */
STM_EVAL_PBInit(BUTTON_TAMPER , BUTTON_MODE_EXTI);
STM_EVAL_PBInit(BUTTON_WAKEUP , BUTTON_MODE_EXTI);
/* Initialize LEDs and LCD available on EVAL board */
STM_EVAL_LEDInit(LED1);
STM_EVAL_LEDInit(LED2);
/* Initialize the LCD */
LCD_Init();
LCD_Clear(LCD_COLOR_WHITE);
/* Set the Back Color */
LCD_SetBackColor(LCD_COLOR_BLUE);
/* Set the Text Color */
LCD_SetTextColor(LCD_COLOR_WHITE);
LCD_DisplayStringLine(LCD_LINE_0,(uint8_t *) " TimeStamp Example " );
LCD_SetFont(&Font12x12);
if (RTC_ReadBackupRegister(RTC_BKP_DR0) != 0x32F2)
{
/* RTC configuration */
RTC_Config();
/* Configure the time&date register */
RTC_TimeRegulate();
/* Display the Date and Time */
RTC_DateShow();
RTC_TimeShow();
}
else
{
/* Check if the Power On Reset flag is set */
if (RCC_GetFlagStatus(RCC_FLAG_PORRST) != RESET)
{
/* Set the Back Color */
LCD_SetBackColor(LCD_COLOR_WHITE);
/* Set the Text Color */
LCD_SetTextColor(LCD_COLOR_GREEN);
LCD_DisplayStringLine(LCD_LINE_2,(uint8_t *) "Power On Reset occurred " );
}
/* Check if the Pin Reset flag is set */
else if (RCC_GetFlagStatus(RCC_FLAG_PINRST) != RESET)
{
/* Set the Back Color */
LCD_SetBackColor(LCD_COLOR_WHITE);
/* Set the Text Color */
LCD_SetTextColor(LCD_COLOR_GREEN);
LCD_DisplayStringLine(LCD_LINE_2,(uint8_t *) "External Reset occurred " );
}
/* Set the Back Color */
LCD_SetBackColor(LCD_COLOR_WHITE);
/* Set the Text Color */
LCD_SetTextColor(LCD_COLOR_GREEN);
LCD_DisplayStringLine(LCD_LINE_3,(uint8_t *) "No need to configure RTC " );
/* Enable the PWR clock */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
/* Allow access to RTC */
PWR_BackupAccessCmd(ENABLE);
/* Wait for RTC APB registers synchronisation */
RTC_WaitForSynchro();
/* Clear the RTC Alarm Flag */
RTC_ClearFlag(RTC_FLAG_ALRAF);
/* Clear the EXTI Line 17 Pending bit (Connected internally to RTC Alarm) */
EXTI_ClearITPendingBit(EXTI_Line17);
/* Display the RTC Time/Date and TimeStamp Time/Date */
RTC_DateShow();
RTC_TimeShow();
}
//.........这里部分代码省略.........
示例12: RTC_Config
/**
* @brief Configure the RTC peripheral by selecting the clock source.
* @param None
* @retval None
*/
static void RTC_Config(void)
{
/* Enable the PWR clock */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
/* Allow access to RTC */
PWR_BackupAccessCmd(ENABLE);
#if defined (RTC_CLOCK_SOURCE_LSI) /* LSI used as RTC source clock*/
/* The RTC Clock may varies due to LSI frequency dispersion. */
/* Enable the LSI OSC */
RCC_LSICmd(ENABLE);
/* Wait till LSI is ready */
while(RCC_GetFlagStatus(RCC_FLAG_LSIRDY) == RESET)
{
}
/* Select the RTC Clock Source */
RCC_RTCCLKConfig(RCC_RTCCLKSource_LSI);
/* ck_spre(1Hz) = RTCCLK(LSI) /(uwAsynchPrediv + 1)*(uwSynchPrediv + 1)*/
uwSynchPrediv = 0xFF;
uwAsynchPrediv = 0x7F;
#elif defined (RTC_CLOCK_SOURCE_LSE) /* LSE used as RTC source clock */
/* Enable the LSE OSC */
RCC_LSEConfig(RCC_LSE_ON);
/* Wait till LSE is ready */
while(RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET)
{
}
/* Select the RTC Clock Source */
RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);
/* ck_spre(1Hz) = RTCCLK(LSE) /(uwAsynchPrediv + 1)*(uwSynchPrediv + 1)*/
uwSynchPrediv = 0xFF;
uwAsynchPrediv = 0x7F;
#else
#error Please select the RTC Clock source inside the main.c file
#endif /* RTC_CLOCK_SOURCE_LSI */
/* Configure the RTC data register and RTC prescaler */
RTC_InitStructure.RTC_AsynchPrediv = uwAsynchPrediv;
RTC_InitStructure.RTC_SynchPrediv = uwSynchPrediv;
RTC_InitStructure.RTC_HourFormat = RTC_HourFormat_24;
/* Check on RTC init */
if (RTC_Init(&RTC_InitStructure) == ERROR)
{
/* Set the Back Color */
LCD_SetBackColor(LCD_COLOR_WHITE);
/* Set the Text Color */
LCD_SetTextColor(LCD_COLOR_RED);
LCD_DisplayStringLine(LCD_LINE_3,(uint8_t *) "RTC Prescaler Config failed " );
}
/* Enable the RTC Clock */
RCC_RTCCLKCmd(ENABLE);
/* Wait for RTC APB registers synchronisation */
RTC_WaitForSynchro();
/* Enable The TimeStamp */
RTC_TimeStampCmd(RTC_TimeStampEdge_Falling, ENABLE);
}
示例13: main
/**
* @brief Main program.
* @param None
* @retval None
*/
int main(void)
{
/*!< At this stage the microcontroller clock setting is already configured,
this is done through SystemInit() function which is called from startup
file (startup_stm32f10x_xx.s) before to branch to application main.
To reconfigure the default setting of SystemInit() function, refer to
system_stm32f10x.c file
*/
/* Initialize LED1 mounted on STM3210X-EVAL board */
STM_EVAL_LEDInit(LED1);
/* USARTx configured as follow:
- BaudRate = 115200 baud
- Word Length = 8 Bits
- One Stop Bit
- No parity
- Hardware flow control disabled (RTS and CTS signals)
- Receive and transmit enabled
*/
USART_InitStructure.USART_BaudRate = 115200;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
STM_EVAL_COMInit(COM1, &USART_InitStructure);
/* NVIC configuration */
NVIC_Configuration();
if (BKP_ReadBackupRegister(BKP_DR1) != 0xA5A5)
{
/* Backup data register value is not correct or not yet programmed (when
the first time the program is executed) */
printf("\r\n\n RTC not yet configured....");
/* RTC Configuration */
RTC_Configuration();
printf("\r\n RTC configured....");
/* Adjust time by values entered by the user on the hyperterminal */
Time_Adjust();
BKP_WriteBackupRegister(BKP_DR1, 0xA5A5);
}
else
{
/* Check if the Power On Reset flag is set */
if (RCC_GetFlagStatus(RCC_FLAG_PORRST) != RESET)
{
printf("\r\n\n Power On Reset occurred....");
}
/* Check if the Pin Reset flag is set */
else if (RCC_GetFlagStatus(RCC_FLAG_PINRST) != RESET)
{
printf("\r\n\n External Reset occurred....");
}
printf("\r\n No need to configure RTC....");
/* Wait for RTC registers synchronization */
RTC_WaitForSynchro();
/* Enable the RTC Second */
RTC_ITConfig(RTC_IT_SEC, ENABLE);
/* Wait until last write operation on RTC registers has finished */
RTC_WaitForLastTask();
}
#ifdef RTCClockOutput_Enable
/* Enable PWR and BKP clocks */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE);
/* Allow access to BKP Domain */
PWR_BackupAccessCmd(ENABLE);
/* Disable the Tamper Pin */
BKP_TamperPinCmd(DISABLE); /* To output RTCCLK/64 on Tamper pin, the tamper
functionality must be disabled */
/* Enable RTC Clock Output on Tamper Pin */
BKP_RTCOutputConfig(BKP_RTCOutputSource_CalibClock);
#endif
/* Clear reset flags */
RCC_ClearFlag();
/* Display time in infinite loop */
Time_Show();
}
示例14: RTC_Init
/**************************************************************/
//程 序 名: RTC_Init
//开 发 者: MingH
//入口参数: 无
//功能说明: RTC 相关寄存器配置初始化, 外部调用
//**************************************************************/
void RTC_Init(void)
{
RTC_NVIC_Configuration(); // RTC 中断配置
if (BKP_ReadBackupRegister(BKP_DR1) != 0xA5A5)
{
/* Backup data register value is not correct or not yet programmed (when
the first time the program is executed) */
printf("\r\n\n RTC not yet configured....");
/* RTC Configuration */
RTC_Configuration();
printf("\r\n RTC configured....");
/* Adjust time by values entered by the user on the hyperterminal */
Time_Adjust();
BKP_WriteBackupRegister(BKP_DR1, 0xA5A5);
}
else
{
/* Check if the Power On Reset flag is set */
if (RCC_GetFlagStatus(RCC_FLAG_PORRST) != RESET)
{
printf("\r\n\n Power On Reset occurred....");
}
/* Check if the Pin Reset flag is set */
else if (RCC_GetFlagStatus(RCC_FLAG_PINRST) != RESET)
{
printf("\r\n\n External Reset occurred....");
}
printf("\r\n No need to configure RTC....");
/* Wait for RTC registers synchronization */
RTC_WaitForSynchro();
/* Enable the RTC Second */
RTC_ITConfig(RTC_IT_SEC, ENABLE);
/* Wait until last write operation on RTC registers has finished */
RTC_WaitForLastTask();
}
#ifdef RTCClockOutput_Enable
/* Enable PWR and BKP clocks */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE);
/* Allow access to BKP Domain */
PWR_BackupAccessCmd(ENABLE);
/* Disable the Tamper Pin */
BKP_TamperPinCmd(DISABLE); /* To output RTCCLK/64 on Tamper pin, the tamper
functionality must be disabled */
/* Enable RTC Clock Output on Tamper Pin */
BKP_RTCOutputConfig(BKP_RTCOutputSource_CalibClock);
#endif
/* Clear reset flags */
RCC_ClearFlag();
}
示例15: HAL_RTC_Configuration
void HAL_RTC_Configuration(void)
{
RTC_InitTypeDef RTC_InitStructure;
EXTI_InitTypeDef EXTI_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
__IO uint32_t AsynchPrediv = 0x7F, SynchPrediv = 0xFF;
/* Configure EXTI Line17(RTC Alarm) to generate an interrupt on rising edge */
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;
EXTI_Init(&EXTI_InitStructure);
/* Enable the RTC Alarm Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = RTC_Alarm_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = RTC_Alarm_IRQ_PRIORITY;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
/* Check if the StandBy flag is set */
if(PWR_GetFlagStatus(PWR_FLAG_SB) != RESET)
{
/* System resumed from STANDBY mode */
/* Wait for RTC APB registers synchronisation */
RTC_WaitForSynchro();
/* Clear the RTC Alarm Flag */
RTC_ClearFlag(RTC_FLAG_ALRAF);
/* Clear the EXTI Line 17 Pending bit (Connected internally to RTC Alarm) */
EXTI_ClearITPendingBit(EXTI_Line17);
/* No need to configure the RTC as the RTC configuration(clock source, enable,
prescaler,...) is kept after wake-up from STANDBY */
}
else
{
/* StandBy flag is not set */
/* Enable LSE */
RCC_LSEConfig(RCC_LSE_ON);
/* Wait till LSE is ready */
while (RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET)
{
//Do nothing
}
/* Select LSE as RTC Clock Source */
RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);
/* Enable RTC Clock */
RCC_RTCCLKCmd(ENABLE);
/* Wait for RTC registers synchronization */
RTC_WaitForSynchro();
/* RTC register configuration done only once */
if (RTC_ReadBackupRegister(RTC_BKP_DR0) != 0xC1C1)
{
/* Configure the RTC data register and RTC prescaler */
RTC_InitStructure.RTC_AsynchPrediv = AsynchPrediv;
RTC_InitStructure.RTC_SynchPrediv = SynchPrediv;
RTC_InitStructure.RTC_HourFormat = RTC_HourFormat_24;
/* Check on RTC init */
if (RTC_Init(&RTC_InitStructure) != ERROR)
{
/* Configure RTC Date and Time Registers if not set - Fixes #480, #580 */
/* Set Date/Time to Epoch 0 (Thu, 01 Jan 1970 00:00:00 GMT) */
HAL_RTC_Initialize_UnixTime();
/* Indicator for the RTC configuration */
RTC_WriteBackupRegister(RTC_BKP_DR0, 0xC1C1);
}
}
}
}