NOTICE: The Processors Wiki will End-of-Life in December of 2020. It is recommended to download any files or other content you may need that are hosted on processors.wiki.ti.com. The site is now set to read only.
The RTC peripheral provides a time reference to applications running on the device. The current date and time is tracked in a set of counter registers that update once per second. The time can be represented in 12- or 24-hour mode (i.e. 1:00 p.m. or 13:00). The calendar and time registers are buffered during reads and writes so that updates do not interfere with the accuracy of the time and date. Alarms are available to interrupt the CPU at a particular time or at periodic time intervals, such as once per minute or once per day. In addition, the RTC can generate CPU interrupts whenever the calendar or time registers are updated, or at programmable periodic intervals. The StarterWare APIs to configure and operate the RTC peripheral are listed in include/rtc.h.
The following guidelines and general procedure should be observed when programming the RTC peripheral.
- Configure the overall system clocks and the functional clocks for RTC. Apply appropriate Pin Multiplexing if required.
- Out of reset, RTC registers are write-protected. To disable this write-protection and to program the RTC registers, specific key values have to be programmed to the KICK registers (KICK0 and KICK1). Use the RTCWriteProtectDisable() API to do this.
- Call the RTC32KClkSourceSelect() API passing appropriate parameters to select either internal clock source or external clock source for providing the 32KHz clock input to the RTC.
- Call the RTC32KClkClockControl() API passing appropriate arguments to enable RTC to receive clock inputs from the previously selected clock source.
- Call the RTCEnable() API to enable the RTC. This ensures that the 32KHz clock input to the RTC is not gated.
- Use RTCTimeSet() to set the specified time in the relevant RTC registers. The time is passed as a parameter to this function. This function sets the second, minute, hour and the meridiem (AM or PM) values in the relevant registers. There are also APIs to set these values individually.
- Call the RTCRun() API immediately after calling RTCTimeSet() to start clock operation (i.e. "ticks").
- Use RTCCalendarSet() to set the specified calendar information in the relevant RTC registers. The calendar information is passed as a parameter to this function. This function sets the day (of the week and of the month), month, and year values in the relevant registers. There are also APIs to set these values individually.
- Call RTCTimeGet() and RTCCalendarGet() to read the current time and calendar information respectively from the relevant registers.
- The user can also enable interrupts to be generated when specific events occur. Use RTCIntTimerEnable() API to enable periodic generation of interrupts. The period between two periodic interrupts could be a second, a minute, an hour or a day.
- RTC peripheral can also generate interrupts when it reaches a certain time and calendar reading. These are called alarm interrupts, and they are enabled using the RTCIntAlarmEnable() API. The alarm time is written to the alarm registers of the RTC.
Note: Text in blue refers to configuration steps applicable to RTC IPs in the following SoCs.