📄 stm32f2xx_rtc.c
字号:
{
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 Configures the RTC output source (AFO_ALARM).
* @param RTC_Output: Specifies which signal will be routed to the RTC output.
* This parameter can be one of the following values:
* @arg RTC_Output_Disable: No output selected
* @arg RTC_Output_AlarmA: signal of AlarmA mapped to output
* @arg RTC_Output_AlarmB: signal of AlarmB mapped to output
* @arg RTC_Output_WakeUp: signal of WakeUp mapped to output
* @param RTC_OutputPolarity: Specifies the polarity of the output signal.
* This parameter can be one of the following:
* @arg RTC_OutputPolarity_High: The output pin is high when the
* ALRAF/ALRBF/WUTF is high (depending on OSEL)
* @arg RTC_OutputPolarity_Low: The output pin is low when the
* ALRAF/ALRBF/WUTF is high (depending on OSEL)
* @retval None
*/
void RTC_OutputConfig(uint32_t RTC_Output, uint32_t RTC_OutputPolarity)
{
/* Check the parameters */
assert_param(IS_RTC_OUTPUT(RTC_Output));
assert_param(IS_RTC_OUTPUT_POL(RTC_OutputPolarity));
/* 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_OSEL | RTC_CR_POL);
/* Configure the output selection and polarity */
RTC->CR |= (uint32_t)(RTC_Output | RTC_OutputPolarity);
/* Enable the write protection for RTC registers */
RTC->WPR = 0xFF;
}
/**
* @}
*/
/** @defgroup RTC_Group7 Coarse Calibration configuration functions
* @brief Coarse Calibration configuration functions
*
@verbatim
===============================================================================
Coarse Calibration configuration functions
===============================================================================
@endverbatim
* @{
*/
/**
* @brief Configures the Coarse calibration parameters.
* @param RTC_CalibSign: specifies the sign of the coarse calibration value.
* This parameter can be one of the following values:
* @arg RTC_CalibSign_Positive: The value sign is positive
* @arg RTC_CalibSign_Negative: The value sign is negative
* @param Value: value of coarse calibration expressed in ppm (coded on 5 bits).
*
* @note This Calibration value should be between 0 and 63 when using negative
* sign with a 2-ppm step.
*
* @note This Calibration value should be between 0 and 126 when using positive
* sign with a 4-ppm step.
*
* @retval An ErrorStatus enumeration value:
* - SUCCESS: RTC Coarse calibration are initialized
* - ERROR: RTC Coarse calibration are not initialized
*/
ErrorStatus RTC_CoarseCalibConfig(uint32_t RTC_CalibSign, uint32_t Value)
{
ErrorStatus status = ERROR;
/* Check the parameters */
assert_param(IS_RTC_CALIB_SIGN(RTC_CalibSign));
assert_param(IS_RTC_CALIB_VALUE(Value));
/* Disable the write protection for RTC registers */
RTC->WPR = 0xCA;
RTC->WPR = 0x53;
/* Set Initialization mode */
if (RTC_EnterInitMode() == ERROR)
{
status = ERROR;
}
else
{
/* Set the coarse calibration value */
RTC->CALIBR = (uint32_t)(RTC_CalibSign | Value);
/* Exit Initialization mode */
RTC_ExitInitMode();
status = SUCCESS;
}
/* Enable the write protection for RTC registers */
RTC->WPR = 0xFF;
return status;
}
/**
* @brief Enables or disables the Coarse calibration process.
* @param NewState: new state of the Coarse calibration.
* This parameter can be: ENABLE or DISABLE.
* @retval An ErrorStatus enumeration value:
* - SUCCESS: RTC Coarse calibration are enabled/disabled
* - ERROR: RTC Coarse calibration are not enabled/disabled
*/
ErrorStatus RTC_CoarseCalibCmd(FunctionalState NewState)
{
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;
/* Set Initialization mode */
if (RTC_EnterInitMode() == ERROR)
{
status = ERROR;
}
else
{
if (NewState != DISABLE)
{
/* Enable the Coarse Calibration */
RTC->CR |= (uint32_t)RTC_CR_DCE;
}
else
{
/* Disable the Coarse Calibration */
RTC->CR &= (uint32_t)~RTC_CR_DCE;
}
/* Exit Initialization mode */
RTC_ExitInitMode();
status = SUCCESS;
}
/* Enable the write protection for RTC registers */
RTC->WPR = 0xFF;
return status;
}
/**
* @brief Enables or disables the RTC clock to be output through the relative pin.
* @param NewState: new state of the digital calibration Output.
* This parameter can be: ENABLE or DISABLE.
* @retval None
*/
void RTC_CalibOutputCmd(FunctionalState NewState)
{
/* 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 RTC clock output */
RTC->CR |= (uint32_t)RTC_CR_COE;
}
else
{
/* Disable the RTC clock output */
RTC->CR &= (uint32_t)~RTC_CR_COE;
}
/* Enable the write protection for RTC registers */
RTC->WPR = 0xFF;
}
/**
* @}
*/
/** @defgroup RTC_Group8 TimeStamp configuration functions
* @brief TimeStamp configuration functions
*
@verbatim
===============================================================================
TimeStamp configuration functions
===============================================================================
@endverbatim
* @{
*/
/**
* @brief Enables or Disables the RTC TimeStamp functionality with the
* specified time stamp pin stimulating edge.
* @param RTC_TimeStampEdge: Specifies the pin edge on which the TimeStamp is
* activated.
* This parameter can be one of the following:
* @arg RTC_TimeStampEdge_Rising: the Time stamp event occurs on the rising
* edge of the related pin.
* @arg RTC_TimeStampEdge_Falling: the Time stamp event occurs on the
* falling edge of the related pin.
* @param NewState: new state of the TimeStamp.
* This parameter can be: ENABLE or DISABLE.
* @retval None
*/
void RTC_TimeStampCmd(uint32_t RTC_TimeStampEdge, FunctionalState NewState)
{
uint32_t tmpreg = 0;
/* Check the parameters */
assert_param(IS_RTC_TIMESTAMP_EDGE(RTC_TimeStampEdge));
assert_param(IS_FUNCTIONAL_STATE(NewState));
/* Get the RTC_CR register and clear the bits to be configured */
tmpreg = (uint32_t)(RTC->CR & (uint32_t)~(RTC_CR_TSEDGE | RTC_CR_TSE));
/* Get the new configuration */
if (NewState != DISABLE)
{
tmpreg |= (uint32_t)(RTC_TimeStampEdge | RTC_CR_TSE);
}
else
{
tmpreg |= (uint32_t)(RTC_TimeStampEdge);
}
/* Disable the write protection for RTC registers */
RTC->WPR = 0xCA;
RTC->WPR = 0x53;
/* Configure the Time Stamp TSEDGE and Enable bits */
RTC->CR = (uint32_t)tmpr
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -