Skip to content

v2.x WDT & RTC libraries #363

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions libraries/RTC/examples/Example1_Get_Time/Example1_Get_Time.ino
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Created: Septempter 27th, 2019

This example demonstrates how to initialize and read from the on-board RTC.

Most SparkFun Artemis boards have the necessary external 32kHz crystal to
enable the RTC. If you are using the Artemis module bare you will either
need an external 32kHz xtal or use the internal LFRC. Read the datasheet
Expand All @@ -12,7 +12,7 @@
This example is based on the Ambiq SDK EVB2 RTC example.
*/

/*
/*
// This file is subject to the terms and conditions defined in
// file 'LICENSE.md', which is part of this source code package.
*/
Expand All @@ -25,28 +25,28 @@ void setup()
Serial.println("SparkFun RTC Example");

// Easily set RTC using the system __DATE__ and __TIME__ macros from compiler
RTC.setToCompilerTime();
rtc.setToCompilerTime();

// // Manually set RTC date and time
// RTC.setTime(0, 50, 59, 12, 3, 6, 20); // 12:59:50.000, June 3rd, 2020 (hund, ss, mm, hh, dd, mm, yy)
// Manually set RTC date and time
// rtc.setTime(0, 50, 59, 12, 3, 6, 20); // 12:59:50.000, June 3rd, 2020 (hund, ss, mm, hh, dd, mm, yy)
}

void loop()
{
RTC.getTime();
rtc.getTime();

Serial.printf("It is now ");
Serial.printf("%d:", RTC.hour);
Serial.printf("%02d:", RTC.minute);
Serial.printf("%02d.", RTC.seconds);
Serial.printf("%02d", RTC.hundredths);
Serial.printf("%d:", rtc.hour);
Serial.printf("%02d:", rtc.minute);
Serial.printf("%02d.", rtc.seconds);
Serial.printf("%02d", rtc.hundredths);

Serial.printf(" %02d/", RTC.month);
Serial.printf("%02d/", RTC.dayOfMonth);
Serial.printf("%02d", RTC.year);
Serial.printf(" %02d/", rtc.month);
Serial.printf("%02d/", rtc.dayOfMonth);
Serial.printf("%02d", rtc.year);

Serial.printf(" Day of week: %d =", RTC.weekday);
Serial.printf(" %s", RTC.textWeekday);
Serial.printf(" Day of week: %d =", rtc.weekday);
Serial.printf(" %s", rtc.textWeekday);

Serial.println();

Expand Down
36 changes: 17 additions & 19 deletions libraries/RTC/examples/Example2_Set_Alarms/Example2_Set_Alarms.ino
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ void setup()
Serial.println("SparkFun RTC Set Alarm Example");

// // Easily set RTC using the system __DATE__ and __TIME__ macros from compiler
// RTC.setToCompilerTime();
// rtc.setToCompilerTime();

// Manually set RTC date and time
RTC.setTime(0, 50, 59, 12, 3, 6, 20); // 12:59:50.000, June 3rd, 2020 (hund, ss, mm, hh, dd, mm, yy)
rtc.setTime(0, 50, 59, 12, 3, 6, 20); // 12:59:50.000, June 3rd, 2020 (hund, ss, mm, hh, dd, mm, yy)

// Set the RTC's alarm
RTC.setAlarm(0, 0, 0, 13, 3, 6); // 13:00:00.000, June 3rd (hund, ss, mm, hh, dd, mm). Note: No year alarm register
rtc.setAlarm(0, 0, 0, 13, 3, 6); // 13:00:00.000, June 3rd (hund, ss, mm, hh, dd, mm). Note: No year alarm register

// Set the RTC alarm mode
/*
Expand All @@ -47,8 +47,8 @@ void setup()
6: Alarm match every minute (hundredths, seconds)
7: Alarm match every second (hundredths)
*/
RTC.setAlarmMode(6); // Set the RTC alarm to match on minutes rollover
RTC.attachInterrupt(); // Attach RTC alarm interrupt
rtc.setAlarmMode(6); // Set the RTC alarm to match on minutes rollover
rtc.attachInterrupt(); // Attach RTC alarm interrupt

// Print the RTC's alarm date and time
Serial.print("Next alarm: "); printAlarm();
Expand Down Expand Up @@ -77,31 +77,29 @@ void loop()
// Print the RTC's current date and time
void printDateTime()
{
RTC.getTime();
char dateTimeBuffer[25];
sprintf(dateTimeBuffer, "20%02d-%02d-%02d %02d:%02d:%02d.%03d",
RTC.year, RTC.month, RTC.dayOfMonth,
RTC.hour, RTC.minute, RTC.seconds, RTC.hundredths);
Serial.println(dateTimeBuffer);
rtc.getTime();
Serial.printf("20%02d-%02d-%02d %02d:%02d:%02d.%03d\n",
rtc.year, rtc.month, rtc.dayOfMonth,
rtc.hour, rtc.minute, rtc.seconds, rtc.hundredths);
}

// Print the RTC's alarm
void printAlarm()
{
RTC.getAlarm();
char alarmBuffer[25];
sprintf(alarmBuffer, "2020-%02d-%02d %02d:%02d:%02d.%03d",
RTC.alarmMonth, RTC.alarmDayOfMonth,
RTC.alarmHour, RTC.alarmMinute,
RTC.alarmSeconds, RTC.alarmHundredths);
Serial.println(alarmBuffer);
rtc.getAlarm();

Serial.printf("2020-%02d-%02d %02d:%02d:%02d.%03d\n",
rtc.alarmMonth, rtc.alarmDayOfMonth,
rtc.alarmHour, rtc.alarmMinute,
rtc.alarmSeconds, rtc.alarmHundredths);
Serial.println();
}

// Interrupt handler for the RTC
extern "C" void am_rtc_isr(void)
{
// Clear the RTC alarm interrupt.
am_hal_rtc_int_clear(AM_HAL_RTC_INT_ALM);
rtc.clearInterrupt();

// Set alarm flag
alarmFlag = true;
Expand Down
18 changes: 9 additions & 9 deletions libraries/RTC/examples/Example3_Test_RTC/Example3_Test_RTC.ino
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ void setup()
Serial.println("Artemis RTC Testing");

// Manually set RTC date and time to the start of 2020 so that RTC contains valid times
RTC.setTime(0, 59, 59, 23, 1, 1, 20); // Set to 1 second before midnight Jan 1
rtc.setTime(0, 59, 59, 23, 1, 1, 20); // Set to 1 second before midnight Jan 1
}

void loop()
{
RTC.setTime(99, 59, 59, 23, RTC.dayOfMonth, RTC.month, RTC.year); // Manually set RTC 1/100th of a second from the next day
previousDay = RTC.weekday;
rtc.setTime(99, 59, 59, 23, rtc.dayOfMonth, rtc.month, rtc.year); // Manually set RTC 1/100th of a second from the next day
previousDay = rtc.weekday;
delay(11); //Allow us to roll from midnight the night before to the new day

printArtemisTime();
Expand All @@ -38,8 +38,8 @@ void printArtemisTime()
char buf[50];
char weekdayBuf[4];

RTC.getTime();
int i = RTC.weekday + 1;
rtc.getTime();
int i = rtc.weekday + 1;
switch (i)
{
case (1):
Expand Down Expand Up @@ -69,15 +69,15 @@ void printArtemisTime()
break;
}

sprintf(buf, "%02d-%02d-%02d (%s) %02d:%02d:%02d.%02d", RTC.year, RTC.month, RTC.dayOfMonth, weekdayBuf, RTC.hour, RTC.minute, RTC.seconds, RTC.hundredths);
sprintf(buf, "%02d-%02d-%02d (%s) %02d:%02d:%02d.%02d", rtc.year, rtc.month, rtc.dayOfMonth, weekdayBuf, rtc.hour, rtc.minute, rtc.seconds, rtc.hundredths);
Serial.print(buf);

//Move the previous day forward one day and make sure it matches today
if ((previousDay + 1) % 7 != RTC.weekday)
if ((previousDay + 1) % 7 != rtc.weekday)
{
Serial.printf(" Error! previousDay: %d today: %d\n", previousDay, RTC.weekday);
Serial.printf(" Error! previousDay: %d today: %d\n", previousDay, rtc.weekday);
while (1){};
}

Serial.println();
}
}
15 changes: 7 additions & 8 deletions libraries/RTC/examples/Example4_Set_Epoch/Example4_Set_Epoch.ino
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ void setup()
Serial.println("SparkFun RTC Set UNIX Epoch Time Example");

// Set the RTC time using UNIX Epoch time
RTC.setEpoch(1591185600); // E.g. 12:00:00, June 3rd, 2020
rtc.setEpoch(1591185600); // E.g. 12:00:00, June 3rd, 2020
}

void loop()
{
// Print UNIX Epoch timestamp
Serial.print("Epoch time: "); Serial.println(RTC.getEpoch());
Serial.print("Epoch time: "); Serial.println(rtc.getEpoch());

// Print RTC's date and time
Serial.print("Timestamp: "); printDateTime();
Expand All @@ -35,10 +35,9 @@ void loop()
// Print the RTC's current date and time
void printDateTime()
{
RTC.getTime();
char dateTime[20];
sprintf(dateTime, "20%02d-%02d-%02d %02d:%02d:%02d",
RTC.year, RTC.month, RTC.dayOfMonth,
RTC.hour, RTC.minute, RTC.seconds);
Serial.println(dateTime);
rtc.getTime();
Serial.printf("20%02d-%02d-%02d %02d:%02d:%02d\n",
rtc.year, rtc.month, rtc.dayOfMonth,
rtc.hour, rtc.minute, rtc.seconds);
Serial.println();
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
Author: Adam Garbo and Nathan Seidle
Created: June 3rdrd, 2020

This example demonstrates how to read and set rolling RTC alarms. Each time
the alarm triggers, a user-specified additional amount of time (seconds,
minutes or hours) can be added to create a rolling RTC alarm. Second,
This example demonstrates how to read and set rolling RTC alarms. Each time
the alarm triggers, a user-specified additional amount of time (seconds,
minutes or hours) can be added to create a rolling RTC alarm. Second,
minute and hour rollovers are handled using modulo calculations.

The current code is configured as a 5-second rolling RTC alarm.
The current code is configured as a 5-second rolling RTC alarm.
*/

/*
// This file is subject to the terms and conditions defined in
// file 'LICENSE.md', which is part of this source code package.
/*
// This file is subject to the terms and conditions defined in
// file 'LICENSE.md', which is part of this source code package.
*/

#include "RTC.h"
Expand All @@ -31,10 +31,10 @@ void setup()
// RTC.setToCompilerTime();

// Manually set RTC date and time
RTC.setTime(0, 50, 59, 12, 3, 6, 20); // 12:59:50.000, June 3rd, 2020 (hund, ss, mm, hh, dd, mm, yy)
rtc.setTime(0, 50, 59, 12, 3, 6, 20); // 12:59:50.000, June 3rd, 2020 (hund, ss, mm, hh, dd, mm, yy)

// Set the RTC's alarm
RTC.setAlarm(0, 0, 0, 13, 3, 6); // 13:00:00.000, June 3rd (hund, ss, mm, hh, dd, mm). Note: No year alarm register
rtc.setAlarm(0, 0, 0, 13, 3, 6); // 13:00:00.000, June 3rd (hund, ss, mm, hh, dd, mm). Note: No year alarm register

// Set the RTC alarm mode
/*
Expand All @@ -47,8 +47,8 @@ void setup()
6: Alarm match every minute (hundredths, seconds)
7: Alarm match every second (hundredths)
*/
RTC.setAlarmMode(6); // Set the RTC alarm to match on minutes rollover
RTC.attachInterrupt(); // Attach RTC alarm interrupt
rtc.setAlarmMode(6); // Set the RTC alarm to match on minutes rollover
rtc.attachInterrupt(); // Attach RTC alarm interrupt

// Print the RTC's alarm date and time
Serial.print("Next alarm: "); printAlarm();
Expand All @@ -66,13 +66,13 @@ void loop()
alarmFlag = false;

// Set the RTC's rolling alarm
RTC.setAlarm(0,
(RTC.seconds + alarmSeconds) % 60,
(RTC.minute + alarmMinutes) % 60,
(RTC.hour + alarmHours) % 24,
RTC.dayOfMonth,
RTC.month);
RTC.setAlarmMode(6);
rtc.setAlarm(0,
(rtc.seconds + alarmSeconds) % 60,
(rtc.minute + alarmMinutes) % 60,
(rtc.hour + alarmHours) % 24,
rtc.dayOfMonth,
rtc.month);
rtc.setAlarmMode(6);

// Print next RTC alarm date and time
Serial.print("Next rolling alarm: "); printAlarm();
Expand All @@ -82,31 +82,29 @@ void loop()
// Print the RTC's current date and time
void printDateTime()
{
RTC.getTime();
char dateTimeBuffer[25];
sprintf(dateTimeBuffer, "20%02d-%02d-%02d %02d:%02d:%02d.%03d",
RTC.year, RTC.month, RTC.dayOfMonth,
RTC.hour, RTC.minute, RTC.seconds, RTC.hundredths);
Serial.println(dateTimeBuffer);
rtc.getTime();
Serial.printf("20%02d-%02d-%02d %02d:%02d:%02d.%03d\n",
rtc.year, rtc.month, rtc.dayOfMonth,
rtc.hour, rtc.minute, rtc.seconds, rtc.hundredths);
Serial.println();
}

// Print the RTC's alarm
void printAlarm()
{
RTC.getAlarm();
char alarmBuffer[25];
sprintf(alarmBuffer, "2020-%02d-%02d %02d:%02d:%02d.%03d",
RTC.alarmMonth, RTC.alarmDayOfMonth,
RTC.alarmHour, RTC.alarmMinute,
RTC.alarmSeconds, RTC.alarmHundredths);
Serial.println(alarmBuffer);
rtc.getAlarm();
Serial.printf("2020-%02d-%02d %02d:%02d:%02d.%03d\n",
rtc.alarmMonth, rtc.alarmDayOfMonth,
rtc.alarmHour, rtc.alarmMinute,
rtc.alarmSeconds, rtc.alarmHundredths);
Serial.println();
}

// Interrupt handler for the RTC
extern "C" void am_rtc_isr(void)
{
// Clear the RTC alarm interrupt.
am_hal_rtc_int_clear(AM_HAL_RTC_INT_ALM);
rtc.clearInterrupt();

// Set alarm flag
alarmFlag = true;
Expand Down
Loading