General

group group_rtc_general_functions

Functions

cy_en_rtc_status_t Cy_RTC_Init(cy_stc_rtc_config_t const *config)

Initializes the RTC driver.

Return

Checking result. If the pointer is NULL, returns an error. See cy_en_rtc_status_t.

Parameters

cy_en_rtc_status_t Cy_RTC_SetDateAndTime(cy_stc_rtc_config_t const *dateTime)

Sets the time and date values into the RTC_TIME and RTC_DATE registers.

note

The function may return CY_RTC_INVALID_STATE if the RTC is busy with previous update. In such situation, user should call this function repetitively with appropriate parameters to ensure that RTC is updated with provided arguments.

Return

A validation check result of date and month. Returns an error, if the date range is invalid. See cy_en_rtc_status_t.

Parameters

void Cy_RTC_GetDateAndTime(cy_stc_rtc_config_t *dateTime)

Gets the current RTC time and date.

The AHB RTC Time and Date register values are stored into the *dateTime structure.

Parameters

cy_en_rtc_status_t Cy_RTC_SetDateAndTimeDirect(uint32_t sec, uint32_t min, uint32_t hour, uint32_t date, uint32_t month, uint32_t year)

Sets the time and date values into the RTC_TIME and RTC_DATE registers using direct time parameters.

The function reads the current 12/24-hour mode, then converts the hour value properly as the mode.

Parameters
  • sec: The second valid range is [0-59].

  • min: The minute valid range is [0-59].

  • hour: The hour valid range is [0-23]. This parameter should be presented in the 24-hour format.

Return

A validation check result of date and month. Returns an error, if the date range is invalid or the RTC time and date set was cancelled: the RTC Write bit was not set, the RTC was synchronizing. See cy_en_rtc_status_t.

Parameters
  • date: The date valid range is [1-31], if the month of February is selected as the Month parameter, then the valid range is [0-29].

  • month: The month valid range is [1-12].

  • year: The year valid range is [0-99].

cy_en_rtc_status_t Cy_RTC_SetHoursFormat(cy_en_rtc_hours_format_t hoursFormat)

Sets the 12/24-hour mode.

Return

A validation check result of RTC register update. See cy_en_rtc_status_t.

Parameters

void Cy_RTC_SelectFrequencyPrescaler(cy_en_rtc_clock_freq_t clkSel)

Selects the RTC pre-scaler value and changes its clock frequency.

If the external 32.768 kHz WCO is absent on the board, the RTC can be driven by a 32.768kHz square clock source or an external 50-Hz or 60-Hz sine-wave clock source, for example the wall AC frequency.

In addition to generating the 32.768 kHz clock from external crystals, the WCO can be sourced by an external clock source (50 Hz or 60Hz), even the wall AC frequency as a timebase. The API helps select between the RTC sources:

  • A 32.768 kHz digital clock source.

  • An external 50-Hz or 60-Hz sine-wave clock source.

Parameters

If you want to use an external 50-Hz or 60-Hz sine-wave clock source to drive the RTC, the next procedure is required:

  1. Disable the WCO

  2. Bypass the WCO using the Cy_SysClk_WcoBypass() function.

  3. Configure both wco_out and wco_in pins. Note that only one of the wco pins should be driven and the other wco pin should be floating, which depends on the source that drives the RTC (*1).

  4. Call Cy_RTC_SelectFrequencyPrescaler(CY_RTC_FREQ_60_HZ), if you want to drive the WCO, for example, with a 60 Hz source.

  5. Enable the WCO.

If you want to use the WCO after using an external 50-Hz or 60-Hz sine-wave clock source:

  1. Disable the WCO.

  2. Switch-off the WCO bypass using the Cy_SysClk_WcoBypass() function.

  3. Drive off the wco pin with an external signal source.

  4. Call Cy_RTC_SelectFrequencyPrescaler(CY_RTC_FREQ_WCO_32768_HZ).

  5. Enable the WCO.

(1) - Refer to the device TRM to know how to configure the wco pins properly and which wco pin should be driven/floating.

warning

There is a limitation to the external clock source frequencies. Only two frequencies are allowed - 50 Hz or 60 Hz. Note that this limitation is related to the RTC pre-scaling feature presented in this function. This limitation is not related to WCO external clock sources which can drive the WCO in Bypass mode.

note

This API is available for CAT1A devices.

void Cy_RTC_SelectClockSource(cy_rtc_clk_select_sources_t clkSel)

note

This API is available for CAT1B devices.

Parameters