Lesson 8 – External RTC With Backup Memory

Motivation

In unique applications such as metering, automation and remote sensing it is essential to monitor the real time. Information about the system must also be available during a power cycling event. Using the internal RTC counter module and FRAM, the MSP430 serves as an affordable solution to this problem.

This project allows for data retrieval in the event of a system-wide power loss.

Background

The RTC counter module will perform the function of an external RTC. The user can the time and read the current time via UART. The 16MHz SMCLK is used for the RTC and UART. Additionally, an external 32kHz clock can be used.

The RTC counter module triggers an interrupt every second. The interrupt service routine (ISR) updates the timestamp in FRAM. This timestamp value will persist during a power cycling event.

Code

The MSP430 is simulating an RTC module. After an initial write command, the program stores the current time. It can be read using RTC_READ_TIME.

An alarm can be set which will toggle an LED once it expires.

Figure 1 below communicates reading the initial RTC time, setting a new time and reading that time.

Figure 1 – Demo
Figure 2 – Code flowchart

The GUI

The RTC can be read by clicking the CURRENT TIMESTAMP button.

A new timestamp can be entered by entering an 8-digit POSIX timestamp in the text box.

The Alarm can be set using the slider control.

Once the Alarm is set, ELAPSED TIME field shows the countdown time and it begins to decrement. Once it reaches zero, the ALARM LED on the GUI turns ON and P1.0 (LED) illuminates.

Figure 3 – GUI demo

NOTE: For long-term use, you must calibrate the RTC to eliminate the drift that accumulates.