Microchip® Advanced Software Framework

Quickstart guide for SAM RTC driver

This is the quickstart guide for the SAM RTC driver, with step-by-step instructions on how to configure and use the driver in a selection of use cases.

The use cases contain several code fragments. The code fragments in the steps for setup can be copied into a custom initialization function, while the steps for usage can be copied into, e.g., the main application function.

Basic use case

In this basic use case, the RTC module is using 32kHz external crystal and configured for 24-hour mode. It will read the current date and time.

Prerequisites

  1. System Clock Management (Sysclock)

Setup steps

Example code

Add to application C-file:

Workflow

  • Note
    Please make sure the external 32kHz crystal is available.

Enable the External 32K crystal :

Wait for 32K crystal ready:

Set default RTC configuration, 24-hour mode .

Usage Steps

Example code

Add to, e.g., main loop in application C-file:

uint32_t hour, minute, second;
uint32_t year, month, day, week;
rtc_get_time(RTC, &hour, &minute, &second);
rtc_get_date(RTC, &year, &month, &day, &week);

Workflow

  1. Start Define the variables for the date and time:
    • uint32_t hour, minute, second;
    • uint32_t year, month, day, week;
  2. Read current time:
  3. Read current date: