RTC Exported Functions

group RTC_Exported_Functions

Functions

void RTC_WriteReg(uint32_t regAddress, uint32_t data)

Fast write RTC register, internal function.

Parameters:
  • regAddress[in] The register address.

  • data[in] Data to be written to the register.

Returns:

None.

void RTC_DeInit(void)

Deinitialize the RTC peripheral registers to their default reset values (turn off clock).

Example usage

void driver_rtc_init(void)
{
    RTC_DeInit();
}

Returns:

None.

void RTC_SetPrescaler(uint16_t value)

Set RTC prescaler value.

Example usage

#define RTC_PRESCALER_VALUE     49
#define RTC_COMP_INDEX          RTC_COMP3
#define RTC_COMP_INDEX_INT      RTC_INT_COMP3
#define RTC_COMP_VALUE          (1000)

void driver_rtc_init(void)
{
    RTC_DeInit();

    RTC_SetPrescaler(RTC_PRESCALER_VALUE);
    RTC_SetCompValue(RTC_COMP_INDEX, RTC_COMP_VALUE);

    RTC_MaskINTConfig(RTC_COMP_INDEX_INT, DISABLE);
    RTC_INTConfig(RTC_COMP_INDEX_INT, ENABLE);

    RTC_NvCmd(ENABLE);
    RTC_Cmd(ENABLE);
}

Parameters:

value[in] The prescaler value to be set. Should be no more than 12 bits!

Returns:

None.

void RTC_Cmd(FunctionalState NewState)

Start or stop the RTC peripheral.

Example usage

#define RTC_PRESCALER_VALUE     49
#define RTC_COMP_INDEX          RTC_COMP3
#define RTC_COMP_INDEX_INT      RTC_INT_COMP3
#define RTC_COMP_VALUE          (1000)

void driver_rtc_init(void)
{
    RTC_DeInit();

    RTC_SetPrescaler(RTC_PRESCALER_VALUE);
    RTC_SetCompValue(RTC_COMP_INDEX, RTC_COMP_VALUE);

    RTC_MaskINTConfig(RTC_COMP_INDEX_INT, DISABLE);
    RTC_INTConfig(RTC_COMP_INDEX_INT, ENABLE);

    RTC_NvCmd(ENABLE);
    RTC_Cmd(ENABLE);
}

Parameters:

NewState[in] New state of the RTC peripheral. This parameter can be one of the following values:

  • ENABLE: Start RTC.

  • DISABLE: Stop RTC.

Returns:

None.

void RTC_INTConfig(E_RTC_INT RTC_INT, FunctionalState NewState)

Enable or disable the specified RTC interrupt source.

Example usage

#define RTC_PRESCALER_VALUE     49
#define RTC_COMP_INDEX          RTC_COMP3
#define RTC_COMP_INDEX_INT      RTC_INT_COMP3
#define RTC_COMP_VALUE          (1000)

void driver_rtc_init(void)
{
    RTC_DeInit();

    RTC_SetPrescaler(RTC_PRESCALER_VALUE);
    RTC_SetCompValue(RTC_COMP_INDEX, RTC_COMP_VALUE);

    RTC_MaskINTConfig(RTC_COMP_INDEX_INT, DISABLE);
    RTC_INTConfig(RTC_COMP_INDEX_INT, ENABLE);

    RTC_NvCmd(ENABLE);
    RTC_Cmd(ENABLE);
}

Parameters:
  • RTC_INT[in] Specify the RTC interrupt source to be enabled or disabled. This parameter can be any combination of the following values, refer to RTC Interrupt Definition.

    • RTC_INT_TICK: Tick interrupt source.

    • RTC_INT_OVF: Counter overflow interrupt.

    • RTC_INT_COMP0: Compare 0 interrupt source.

    • RTC_INT_COMP1: Compare 1 interrupt source.

    • RTC_INT_COMP2: Compare 2 interrupt source.

    • RTC_INT_COMP3: Compare 3 interrupt source.

    • RTC_INT_PRE_COMP: Prescale compare interrupt source.

    • RTC_INT_PRE_COMP3: Prescale & compare 3 interrupt source.

  • NewState[in] New state of the specified RTC interrupt. This parameter can be: ENABLE or DISABLE.

Returns:

None.

void RTC_WKConfig(E_RTC_WK RTC_WK, FunctionalState NewState)

Enable or disable the specified RTC wakeup function.

Example usage

#define RTC_PRESCALER_VALUE     49
#define RTC_COMP_INDEX          RTC_COMP3
#define RTC_COMP_INDEX_INT      RTC_INT_COMP3
#define RTC_COMP_VALUE          (1000)

void driver_rtc_init(void)
{
    RTC_DeInit();

    RTC_SetPrescaler(RTC_PRESCALER_VALUE);
    RTC_SetCompValue(RTC_COMP_INDEX, RTC_COMP_VALUE);

    RTC_MaskINTConfig(RTC_COMP_INDEX_INT, DISABLE);
    RTC_INTConfig(RTC_COMP_INDEX_INT, ENABLE);

    RTC_NvCmd(ENABLE);
    RTC_Cmd(ENABLE);
}

Parameters:
  • RTC_WK – Specify the RTC wakeup function to be enabled or disabled. This parameter can be any combination of the following values, refer to RTC Wakeup Definition.

    • RTC_WK_TICK: tick wakeup function

    • RTC_WK_OVF: tick wakeup function

    • RTC_WK_PRE_CMP: prescale compare wakeup function

    • RTC_WK_PRE_CMP3: prescale & compare 3 wakeup function

    • RTC_WK_COMP0GT: compare 0 gt wakeup function

    • RTC_WK_COMP1GT: compare 1 gt wakeup function

    • RTC_WK_COMP2GT: compare 2 gt wakeup function

    • RTC_WK_COMP3GT: compare 3 gt wakeup function

    • RTC_WK_CMP0: compare 0 wakeup function

    • RTC_WK_CMP1: compare 1 wakeup function

    • RTC_WK_CMP2: compare 2 wakeup function

    • RTC_WK_CMP3: compare 3 wakeup function

  • NewState – new state of the specified RTC wakeup function. This parameter can be: ENABLE or DISABLE.

Returns:

None.

void RTC_NvCmd(FunctionalState NewState)

Enable RTC interrupt signal to CPU NVIC.

Example usage

#define RTC_PRESCALER_VALUE     49
#define RTC_COMP_INDEX          RTC_COMP3
#define RTC_COMP_INDEX_INT      RTC_INT_COMP3
#define RTC_COMP_VALUE          (1000)

void driver_rtc_init(void)
{
    RTC_DeInit();

    RTC_SetPrescaler(RTC_PRESCALER_VALUE);
    RTC_SetCompValue(RTC_COMP_INDEX, RTC_COMP_VALUE);

    RTC_MaskINTConfig(RTC_COMP_INDEX_INT, DISABLE);
    RTC_INTConfig(RTC_COMP_INDEX_INT, ENABLE);

    RTC_NvCmd(ENABLE);
    RTC_Cmd(ENABLE);
}

Parameters:

NewState[in] Enable or disable the RTC interrupt signal to MCU. This parameter can be: ENABLE or DISABLE.

Returns:

None.

void RTC_SystemWakeupConfig(FunctionalState NewState)

Enable or disable the system wakeup function of RTC.

Example usage

void rtc_demo(void)
{
    RTC_SystemWakeupConfig(ENABLE);
}

Parameters:

NewState[in] New state of the wakeup function. This parameter can be: ENABLE or DISABLE.

Returns:

None.

void RTC_ResetCounter(void)

Reset the counter value of RTC.

Example usage

void rtc_demo(void)
{
    RTC_ResetCounter();
    RTC_Cmd(ENABLE);
}

Returns:

None.

void RTC_ResetPrescalerCounter(void)

Reset prescaler counter value of RTC.

Example usage

void rtc_demo(void)
{
    RTC_ResetPrescalerCounter();
    RTC_Cmd(ENABLE);
}

Returns:

None.

ITStatus RTC_GetINTStatus(E_RTC_INT RTC_INT)

Check whether the specified RTC interrupt is set.

Example usage

void rtc_demo(void)
{
    ITStatus int_status = RTC_GetINTStatus(RTC_INT_COMP0);
}

Parameters:

RTC_INT[in] Specify the RTC interrupt source to be enabled or disabled. This parameter can be any combination of the following values, refer to RTC Interrupt Definition.

  • RTC_INT_TICK: RTC tick interrupt source.

  • RTC_INT_COMP0: Compare 0 interrupt source.

  • RTC_INT_COMP1: Compare 1 interrupt source.

  • RTC_INT_COMP2: Compare 2 interrupt source.

  • RTC_INT_COMP3: Compare 3 interrupt source.

  • RTC_INT_PRE_COMP: Prescale compare interrupt source.

  • RTC_INT_PRE_COMP3: Prescale & compare 3 interrupt source.

Returns:

The new state of RTC_INT (SET or RESET).

void RTC_ClearINTPendingBit(E_RTC_INT RTC_INT)

Clear the interrupt pending bits of RTC.

Example usage

void rtc_demo(void)
{
    RTC_ClearINTPendingBit(RTC_INT_COMP0);
}

Parameters:

RTC_INT[in] Specify the RTC interrupt flag to clear. This parameter can be any combination of the following values, refer to RTC Interrupt Definition.

  • RTC_INT_TICK: RTC tick interrupt source.

  • RTC_INT_OVF: RTC counter overflow interrupt source.

  • RTC_INT_COMP0: Compare 0 interrupt source.

  • RTC_INT_COMP1: Compare 1 interrupt source.

  • RTC_INT_COMP2: Compare 2 interrupt source.

  • RTC_INT_COMP3: Compare 3 interrupt source.

  • RTC_INT_PRE_COMP: Prescale compare interrupt source.

  • RTC_INT_PRE_COMP3: Prescale & compare 3 interrupt source.

Returns:

None.

ITStatus RTC_GetWakeupStatus(E_RTC_WK RTC_WK)

Check whether the specified RTC wakeup state is set or not.

Parameters:

RTC_WK – Specify the RTC interrupt source to be enabled or disabled. This parameter can be any combination of the following values, refer to RTC Wakeup Definition.

  • RTC_WK_TICK: Tick wakeup function.

  • RTC_WK_OVF: Tick wakeup function.

  • RTC_WK_PRE_CMP: Prescale compare wakeup function.

  • RTC_WK_PRE_CMP3: Prescale & compare 3 wakeup function.

  • RTC_WK_COMP0GT: Compare 0 gt wakeup function.

  • RTC_WK_COMP1GT: Compare 1 gt wakeup function.

  • RTC_WK_COMP2GT: Compare 2 gt wakeup function.

  • RTC_WK_COMP3GT: Compare 3 gt wakeup function.

  • RTC_WK_CMP0: Compare 0 wakeup function.

  • RTC_WK_CMP1: Compare 1 wakeup function.

  • RTC_WK_CMP2: Compare 2 wakeup function.

  • RTC_WK_CMP3: Compare 3 wakeup function.

Returns:

The new state of RTC_INT (SET or RESET).

void RTC_ClearWakeupStatusBit(E_RTC_WK RTC_WK)

Clear the wakeup status bits of RTC.

Parameters:

RTC_WK – Specify the RTC wakeup flag to clear. This parameter can be any combination of the following values, refer to RTC Wakeup Definition.

  • RTC_WK_TICK: Tick wakeup function.

  • RTC_WK_OVF: Tick wakeup function.

  • RTC_WK_PRE_CMP: Prescale compare wakeup function.

  • RTC_WK_PRE_CMP3: Prescale & compare 3 wakeup function.

  • RTC_WK_COMP0GT: Compare 0 gt wakeup function.

  • RTC_WK_COMP1GT: Compare 1 gt wakeup function.

  • RTC_WK_COMP2GT: Compare 2 gt wakeup function.

  • RTC_WK_COMP3GT: Compare 3 gt wakeup function.

  • RTC_WK_CMP0: Compare 0 wakeup function.

  • RTC_WK_CMP1: Compare 1 wakeup function.

  • RTC_WK_CMP2: Compare 2 wakeup function.

  • RTC_WK_CMP3: Compare 3 wakeup function.

Returns:

None.

void RTC_ClearCompINT(E_RTC_COMP_INDEX index)

Clear the interrupt pending bit of the select comparator of RTC.

Example usage

void rtc_demo(void)
{
    RTC_ClearCompINT(0);
}

Parameters:

index[in] the comparator number, refer to RTC Comparator Index.

Returns:

None.

void RTC_ClearOverFlowINT(void)

Clear the overflow interrupt pending bit of RTC.

Example usage

void rtc_demo(void)
{
    RTC_ClearOverFlowINT();
}

Returns:

None.

void RTC_ClearTickINT(void)

Clear the tick interrupt pending bit of RTC.

Example usage

void rtc_demo(void)
{
    RTC_ClearTickINT();
}

Returns:

None.

void RTC_SetCompValue(E_RTC_COMP_INDEX index, uint32_t value)

Set RTC comparator value.

Example usage

#define RTC_PRESCALER_VALUE     49
#define RTC_COMP_INDEX          RTC_COMP3
#define RTC_COMP_INDEX_INT      RTC_INT_COMP3
#define RTC_COMP_VALUE          (1000)

void driver_rtc_init(void)
{
    RTC_DeInit();

    RTC_SetPrescaler(RTC_PRESCALER_VALUE);
    RTC_SetCompValue(RTC_COMP_INDEX, RTC_COMP_VALUE);

    RTC_MaskINTConfig(RTC_COMP_INDEX_INT, DISABLE);
    RTC_INTConfig(RTC_COMP_INDEX_INT, ENABLE);

    RTC_NvCmd(ENABLE);
    RTC_Cmd(ENABLE);
}

Parameters:
  • index[in] The comparator number can be 0 ~ 3.

  • value[in] The comparator value to be set. Should be no more than 24 bits!

Returns:

None.

void RTC_SetCompGTValue(E_RTC_COMPGT_INDEX index, uint32_t value)

Set RTC comparator GT value.

Example usage

#define RTC_PRESCALER_VALUE     49
#define RTC_COMP_INDEX          RTC_COMP3
#define RTC_COMP_INDEX_INT      RTC_INT_COMP3
#define RTC_COMP_VALUE          (1000)

void driver_rtc_init(void)
{
    RTC_DeInit();

    RTC_SetPrescaler(RTC_PRESCALER_VALUE);
    RTC_SetCompValue(RTC_COMP_INDEX, RTC_COMP_VALUE);

    RTC_MaskINTConfig(RTC_COMP_INDEX_INT, DISABLE);
    RTC_INTConfig(RTC_COMP_INDEX_INT, ENABLE);

    RTC_NvCmd(ENABLE);
    RTC_Cmd(ENABLE);
}

Parameters:
  • index[in] The comparator GT number, can be 0 ~ 3.

  • value[in] The comparator value to be set.

Returns:

None.

void RTC_SetPreCompValue(uint32_t value)

Set RTC prescaler comparator value.

Example usage

#define RTC_PRESCALER_VALUE     (3200 - 1)//max 4095
#define RTC_PRECOMP_VALUE       (320)//max 4095
#define RTC_COMP3_VALUE         (10)

void driver_rtc_init(void)
{
    RTC_DeInit();

    RTC_SetPrescaler(RTC_PRESCALER_VALUE);
    RTC_SetPreCompValue(RTC_PRECOMP_VALUE);
    RTC_SetCompValue(RTC_COMP3, RTC_COMP3_VALUE);

    RTC_MaskINTConfig(RTC_INT_PRE_COMP3, DISABLE);
    RTC_INTConfig(RTC_INT_PRE_COMP3, ENABLE);

    RTC_NvCmd(ENABLE);
    RTC_Cmd(ENABLE);
}

Parameters:

value[in] The comparator value to be set. Should be no more than 12 bits!

Returns:

None.

uint32_t RTC_GetCounter(void)

Get counter value of RTC.

Example usage

void rtc_demo(void)
{
    uint32_t counter = RTC_GetCounter();
}

Returns:

The counter value.

uint32_t RTC_GetPreCounter(void)

Get prescaler counter value of RTC.

Example usage

void rtc_demo(void)
{
    uint32_t pre_counter = RTC_GetPreCounter();
}

Returns:

The prescaler counter value.

uint32_t RTC_GetCompValue(E_RTC_COMP_INDEX index)

Get RTC comparator value.

Example usage

void rtc_demo(void)
{
    uint32_t data = RTC_GetCompValue(0);
}

Parameters:

index[in] The comparator number.

Returns:

The comparator value.

uint32_t RTC_GetCompGTValue(E_RTC_COMPGT_INDEX index)

Get RTC comparator GT value.

Example usage

void rtc_demo(void)
{
    uint32_t data = RTC_GetCompGTValue(0);
}

Parameters:

index[in] The comparator number 0~3.

Returns:

The comparator value.

uint32_t RTC_GetPreCompValue(void)

Get RTC prescaler comparator value.

Example usage

void rtc_demo(void)
{
    uint32_t data = RTC_GetPreCompValue();
}

Returns:

The prescaler comparator value.

void RTC_WriteBackupReg(uint32_t value)

Write backup register for store time information.

Example usage

void rtc_demo(void)
{
    RTC_WriteBackupReg(0x01020304);
}

Parameters:

value[in] value write to backup register.

Returns:

None.

uint32_t RTC_ReadBackupReg(void)

Read backup register.

Example usage

void rtc_demo(void)
{
    uint32_t reg_data = RTC_ReadBackupReg();
}

Returns:

Register value.