📄 stm32f4xx_rtc.c
字号:
/* Enable the write protection for RTC registers */
RTC->WPR = 0xFF;
return status;
}
/**
* @brief Configure the RTC AlarmA/B Subseconds value and mask.*
* @note This function is performed only when the Alarm is disabled.
* @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
* @param RTC_AlarmSubSecondValue: specifies the Subseconds value.
* This parameter can be a value from 0 to 0x00007FFF.
* @param RTC_AlarmSubSecondMask: specifies the Subseconds Mask.
* This parameter can be any combination of the following values:
* @arg RTC_AlarmSubSecondMask_All : All Alarm SS fields are masked.
* There is no comparison on sub seconds for Alarm.
* @arg RTC_AlarmSubSecondMask_SS14_1 : SS[14:1] are don't care in Alarm comparison.
* Only SS[0] is compared
* @arg RTC_AlarmSubSecondMask_SS14_2 : SS[14:2] are don't care in Alarm comparison.
* Only SS[1:0] are compared
* @arg RTC_AlarmSubSecondMask_SS14_3 : SS[14:3] are don't care in Alarm comparison.
* Only SS[2:0] are compared
* @arg RTC_AlarmSubSecondMask_SS14_4 : SS[14:4] are don't care in Alarm comparison.
* Only SS[3:0] are compared
* @arg RTC_AlarmSubSecondMask_SS14_5 : SS[14:5] are don't care in Alarm comparison.
* Only SS[4:0] are compared
* @arg RTC_AlarmSubSecondMask_SS14_6 : SS[14:6] are don't care in Alarm comparison.
* Only SS[5:0] are compared
* @arg RTC_AlarmSubSecondMask_SS14_7 : SS[14:7] are don't care in Alarm comparison.
* Only SS[6:0] are compared
* @arg RTC_AlarmSubSecondMask_SS14_8 : SS[14:8] are don't care in Alarm comparison.
* Only SS[7:0] are compared
* @arg RTC_AlarmSubSecondMask_SS14_9 : SS[14:9] are don't care in Alarm comparison.
* Only SS[8:0] are compared
* @arg RTC_AlarmSubSecondMask_SS14_10: SS[14:10] are don't care in Alarm comparison.
* Only SS[9:0] are compared
* @arg RTC_AlarmSubSecondMask_SS14_11: SS[14:11] are don't care in Alarm comparison.
* Only SS[10:0] are compared
* @arg RTC_AlarmSubSecondMask_SS14_12: SS[14:12] are don't care in Alarm comparison.
* Only SS[11:0] are compared
* @arg RTC_AlarmSubSecondMask_SS14_13: SS[14:13] are don't care in Alarm comparison.
* Only SS[12:0] are compared
* @arg RTC_AlarmSubSecondMask_SS14 : SS[14] is don't care in Alarm comparison.
* Only SS[13:0] are compared
* @arg RTC_AlarmSubSecondMask_None : SS[14:0] are compared and must match
* to activate alarm
* @retval None
*/
void RTC_AlarmSubSecondConfig(uint32_t RTC_Alarm, uint32_t RTC_AlarmSubSecondValue, uint32_t RTC_AlarmSubSecondMask)
{
uint32_t tmpreg = 0;
/* Check the parameters */
assert_param(IS_RTC_ALARM(RTC_Alarm));
assert_param(IS_RTC_ALARM_SUB_SECOND_VALUE(RTC_AlarmSubSecondValue));
assert_param(IS_RTC_ALARM_SUB_SECOND_MASK(RTC_AlarmSubSecondMask));
/* Disable the write protection for RTC registers */
RTC->WPR = 0xCA;
RTC->WPR = 0x53;
/* Configure the Alarm A or Alarm B SubSecond registers */
tmpreg = (uint32_t) (uint32_t)(RTC_AlarmSubSecondValue) | (uint32_t)(RTC_AlarmSubSecondMask);
if (RTC_Alarm == RTC_Alarm_A)
{
/* Configure the AlarmA SubSecond register */
RTC->ALRMASSR = tmpreg;
}
else
{
/* Configure the Alarm B SubSecond register */
RTC->ALRMBSSR = tmpreg;
}
/* Enable the write protection for RTC registers */
RTC->WPR = 0xFF;
}
/**
* @brief Gets the RTC Alarm Subseconds value.
* @param RTC_Alarm: specifies the alarm to be read.
* 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
* @param None
* @retval RTC Alarm Subseconds value.
*/
uint32_t RTC_GetAlarmSubSecond(uint32_t RTC_Alarm)
{
uint32_t tmpreg = 0;
/* Get the RTC_ALRMxR register */
if (RTC_Alarm == RTC_Alarm_A)
{
tmpreg = (uint32_t)((RTC->ALRMASSR) & RTC_ALRMASSR_SS);
}
else
{
tmpreg = (uint32_t)((RTC->ALRMBSSR) & RTC_ALRMBSSR_SS);
}
return (tmpreg);
}
/**
* @}
*/
/** @defgroup RTC_Group4 WakeUp Timer configuration functions
* @brief WakeUp Timer configuration functions
*
@verbatim
===============================================================================
WakeUp Timer configuration functions
===============================================================================
This section provide functions allowing to program and read the RTC WakeUp.
@endverbatim
* @{
*/
/**
* @brief Configures the RTC Wakeup clock source.
* @note The WakeUp Clock source can only be changed when the RTC WakeUp
* is disabled (Use the RTC_WakeUpCmd(DISABLE)).
* @param RTC_WakeUpClock: Wakeup Clock source.
* This parameter can be one of the following values:
* @arg RTC_WakeUpClock_RTCCLK_Div16: RTC Wakeup Counter Clock = RTCCLK/16
* @arg RTC_WakeUpClock_RTCCLK_Div8: RTC Wakeup Counter Clock = RTCCLK/8
* @arg RTC_WakeUpClock_RTCCLK_Div4: RTC Wakeup Counter Clock = RTCCLK/4
* @arg RTC_WakeUpClock_RTCCLK_Div2: RTC Wakeup Counter Clock = RTCCLK/2
* @arg RTC_WakeUpClock_CK_SPRE_16bits: RTC Wakeup Counter Clock = CK_SPRE
* @arg RTC_WakeUpClock_CK_SPRE_17bits: RTC Wakeup Counter Clock = CK_SPRE
* @retval None
*/
void RTC_WakeUpClockConfig(uint32_t RTC_WakeUpClock)
{
/* Check the parameters */
assert_param(IS_RTC_WAKEUP_CLOCK(RTC_WakeUpClock));
/* Disable the write protection for RTC registers */
RTC->WPR = 0xCA;
RTC->WPR = 0x53;
/* Clear the Wakeup Timer clock source bits in CR register */
RTC->CR &= (uint32_t)~RTC_CR_WUCKSEL;
/* Configure the clock source */
RTC->CR |= (uint32_t)RTC_WakeUpClock;
/* Enable the write protection for RTC registers */
RTC->WPR = 0xFF;
}
/**
* @brief Configures the RTC Wakeup counter.
* @note The RTC WakeUp counter can only be written when the RTC WakeUp
* is disabled (Use the RTC_WakeUpCmd(DISABLE)).
* @param RTC_WakeUpCounter: specifies the WakeUp counter.
* This parameter can be a value from 0x0000 to 0xFFFF.
* @retval None
*/
void RTC_SetWakeUpCounter(uint32_t RTC_WakeUpCounter)
{
/* Check the parameters */
assert_param(IS_RTC_WAKEUP_COUNTER(RTC_WakeUpCounter));
/* Disable the write protection for RTC registers */
RTC->WPR = 0xCA;
RTC->WPR = 0x53;
/* Configure the Wakeup Timer counter */
RTC->WUTR = (uint32_t)RTC_WakeUpCounter;
/* Enable the write protection for RTC registers */
RTC->WPR = 0xFF;
}
/**
* @brief Returns the RTC WakeUp timer counter value.
* @param None
* @retval The RTC WakeUp Counter value.
*/
uint32_t RTC_GetWakeUpCounter(void)
{
/* Get the counter value */
return ((uint32_t)(RTC->WUTR & RTC_WUTR_WUT));
}
/**
* @brief Enables or Disables the RTC WakeUp timer.
* @param NewState: new state of the WakeUp timer.
* This parameter can be: ENABLE or DISABLE.
* @retval None
*/
ErrorStatus RTC_WakeUpCmd(FunctionalState NewState)
{
__IO uint32_t wutcounter = 0x00;
uint32_t wutwfstatus = 0x00;
ErrorStatus status = ERROR;
/* Check the parameters */
assert_param(IS_FUNCTIONAL_STATE(NewState));
/* Disable the write protection for RTC registers */
RTC->WPR = 0xCA;
RTC->WPR = 0x53;
if (NewState != DISABLE)
{
/* Enable the Wakeup Timer */
RTC->CR |= (uint32_t)RTC_CR_WUTE;
status = SUCCESS;
}
else
{
/* Disable the Wakeup Timer */
RTC->CR &= (uint32_t)~RTC_CR_WUTE;
/* Wait till RTC WUTWF flag is set and if Time out is reached exit */
do
{
wutwfstatus = RTC->ISR & RTC_ISR_WUTWF;
wutcounter++;
} while((wutcounter != INITMODE_TIMEOUT) && (wutwfstatus == 0x00));
if ((RTC->ISR & RTC_ISR_WUTWF) == RESET)
{
status = ERROR;
}
else
{
status = SUCCESS;
}
}
/* Enable the write protection for RTC registers */
RTC->WPR = 0xFF;
return status;
}
/**
* @}
*/
/** @defgroup RTC_Group5 Daylight Saving configuration functions
* @brief Daylight Saving configuration functions
*
@verbatim
===============================================================================
Daylight Saving configuration functions
===============================================================================
This section provide functions allowing to configure the RTC DayLight Saving.
@endverbatim
* @{
*/
/**
* @brief Adds or substract one hour from the current time.
* @param RTC_DayLightSaveOperation: the value of hour adjustment.
* This parameter can be one of the following values:
* @arg RTC_DayLightSaving_SUB1H: Substract one hour (winter time)
* @arg RTC_DayLightSaving_ADD1H: Add one hour (summer time)
* @param RTC_StoreOperation: Specifies the value to be written in the BCK bit
* in CR register to store the operation.
* This parameter can be one of the following values:
* @arg RTC_StoreOperation_Reset: BCK Bit Reset
* @arg RTC_StoreOperation_Set: BCK Bit Set
* @retval None
*/
void RTC_DayLightSavingConfig(uint32_t RTC_DayLightSaving, uint32_t RTC_StoreOperation)
{
/* Check the parameters */
assert_param(IS_RTC_DAYLIGHT_SAVING(RTC_DayLightSaving));
assert_param(IS_RTC_STORE_OPERATION(RTC_StoreOperation));
/* Disable the write protection for RTC registers */
RTC->WPR = 0xCA;
RTC->WPR = 0x53;
/* Clear the bits to be configured */
RTC->CR &= (uint32_t)~(RTC_CR_BCK);
/* Configure the RTC_CR register */
RTC->CR |= (uint32_t)(RTC_DayLightSaving | RTC_StoreOperation);
/* Enable the write protection for RTC registers */
RTC->WPR = 0xFF;
}
/**
* @brief Returns the RTC Day Light Saving stored operation.
* @param None
* @retval RTC Day Light Saving stored operation.
* - RTC_StoreOperation_Reset
* - RTC_StoreOperation_Set
*/
uint32_t RTC_GetStoreOperation(void)
{
return (RTC->CR & RTC_CR_BCK);
}
/**
* @}
*/
/** @defgroup RTC_Group6 Output pin Configuration function
* @brief Output pin Configuration function
*
@verbatim
===============================================================================
Output pin Configuration function
===============================================================================
This section provide functions allowing to configure the RTC Output source.
@endverbatim
* @{
*/
/**
* @brief
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -