Microchip® Advanced Software Framework

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
RTC Example

Purpose

This basic example shows how to use the Real-Time Clock (RTC) peripheral available on the SAM microcontrollers. The RTC enables easy time and date management and allows the user to monitor events like a configurable alarm, second change, calendar change, and so on.

Requirements

This example can be used with SAM evaluation kits.

Description

Upon startup, the program displays the currently set time and date and a menu to perform the following:

Menu:
t - Set time
d - Set date
i - Set time alarm
m - Set date alarm
c - Clear the alarm notification (only if it has been triggered)
w - Generate Waveform

"w" is an additional option for SAM3S8, SAM3SD8, SAM4S, SAM4C, SAM4CP, SAM4CM SAMV71, SAMV70, SAME70 and SAMS70. An RTC output can be programmed to generate several waveforms, including a prescaled clock derived from slow clock.

Setting the time, date and time alarm is done by using Menu option, and the display is updated accordingly.

The time alarm is triggered only when the second, minute and hour match the preset values; the date alarm is triggered only when the month and date match the preset values.

Generating waveform is done by using Menu option "w" and a menu to perform the following:

Menu:
0 - No Waveform
1 - 1 Hz square wave
2 - 32 Hz square wave
3 - 64 Hz square wave
4 - 512 Hz square wave
5 - Toggles when alarm flag rise
6 - Copy of the alarm flag
7 - Duty cycle programmable pulse
8 - Quit
Note
The example is using RC oscillator by default. This would generate an accuracy problem for the RTC if not calibrated. It is recommended to use an external 32KHz crystal to get high accuracy. How to initialize RTC with external 32KHz crystal can be referred at Quickstart guide for SAM RTC driver.
In sam4c_ek board, please use SWD instead of JTAG because RTCOUT share pin with JTAG interface. Otherwise there is a debug issue when enable wave output.

Usage

  1. Build the program and download it into the evaluation board.
  2. On the computer, open and configure a terminal application (e.g., HyperTerminal on Microsoft Windows) with these settings:
    • 115200 bauds
    • 8 bits of data
    • No parity
    • 1 stop bit
    • No flow control
  3. Start the application.
  4. In the terminal window, the following text should appear:
    -- RTC Example xxx --
    -- xxxxxx-xx
    -- Compiled: xxx xx xxxx xx:xx:xx --
    Menu:
    t - Set time
    d - Set date
    i - Set time alarm
    m - Set date alarm
  5. Press one of the keys listed in the menu to perform the corresponding action.