Skip to content

Improved RTC Functionality #170

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 53 commits into from
Jul 16, 2020
Merged
Show file tree
Hide file tree
Changes from 50 commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
b1d3cfa
Update RTC
adamgarbo Apr 22, 2020
0d7b0a3
Update RTC.h
adamgarbo Apr 23, 2020
ada4050
Update RTC.cpp
adamgarbo Apr 23, 2020
ad336ad
Update RTC.h
adamgarbo Apr 23, 2020
ba5c816
Update RTC.cpp
adamgarbo Apr 23, 2020
d10ee3f
Update keywords.txt
adamgarbo Apr 23, 2020
17ca26f
Update RTC.cpp
adamgarbo Apr 23, 2020
bf780ab
Update RTC.cpp
adamgarbo Apr 23, 2020
f4d55d1
Update keywords.txt
adamgarbo Apr 23, 2020
2f8ce51
Merge branch 'rtcAlarms' of https://github.com/adamgarbo/Arduino_Apol…
adamgarbo Apr 23, 2020
18c1e6f
Update RTC.h
adamgarbo Apr 24, 2020
0043bf3
Update RTC.cpp
adamgarbo Apr 24, 2020
f3d9c7e
Update keywords.txt
adamgarbo Apr 24, 2020
da71acb
Update RTC.h
adamgarbo Apr 24, 2020
cd53b25
Update keywords.txt
adamgarbo Apr 24, 2020
493200c
Update RTC.cpp
adamgarbo Apr 24, 2020
5fa9db4
Update Example3_TestRTC.ino
adamgarbo Apr 25, 2020
28504be
Update Example2_RTCwithSleep.ino
adamgarbo Apr 25, 2020
ab7447d
Update Example1_getTime.ino
adamgarbo Apr 25, 2020
3d80369
Merge remote-tracking branch 'upstream/master' into rtcAlarms
adamgarbo May 23, 2020
69cc615
Update RTC.h
adamgarbo May 23, 2020
6ae1208
Create Example1_Get_Time.ino
adamgarbo May 23, 2020
fbcdc1d
Delete Example1_getTime.ino
adamgarbo May 23, 2020
a53782e
Create Example2_RTC_Sleep.ino
adamgarbo May 23, 2020
d16b64b
Delete Example2_RTCwithSleep.ino
adamgarbo May 23, 2020
9b18daa
Create Example3_Test_RTC.ino
adamgarbo May 23, 2020
d833ca1
Delete Example3_TestRTC.ino
adamgarbo May 23, 2020
2cf56bf
Create Example4_Set_Epoch.ino
adamgarbo May 23, 2020
bad7234
Create Example5_Set_Alarms.ino
adamgarbo May 23, 2020
ea2e7ea
Create Example6_Rolling_Alarms.ino
adamgarbo May 23, 2020
41e2914
Update Example6_Rolling_Alarms.ino
adamgarbo May 23, 2020
55571c5
Update Example6_Rolling_Alarms.ino
adamgarbo May 26, 2020
7dafea2
Update Example6_Rolling_Alarms.ino
adamgarbo May 26, 2020
9d2390b
Delete Example2_RTC_Sleep.ino
adamgarbo Jun 3, 2020
0a7c956
Delete Example5_Set_Alarms.ino
adamgarbo Jun 3, 2020
ac0bcd0
Delete Example6_Rolling_Alarms.ino
adamgarbo Jun 3, 2020
ca602fe
Update Example1_Get_Time.ino
adamgarbo Jun 3, 2020
877ac2d
Create Example2_Set_Alarms.ino
adamgarbo Jun 3, 2020
6847614
Update Example3_Test_RTC.ino
adamgarbo Jun 3, 2020
c23d225
Update Example4_Set_Epoch.ino
adamgarbo Jun 3, 2020
3383950
Create Example5_Rolling_Alarms.ino
adamgarbo Jun 3, 2020
f3f7ac7
Create Example6_LowPower_Alarm.ino
adamgarbo Jun 3, 2020
2432faa
Update RTC.cpp
adamgarbo Jun 3, 2020
ebb80e5
Update library.properties
adamgarbo Jun 3, 2020
e691f2f
Update RTC alarm comparisons
adamgarbo Jun 3, 2020
f27f5a7
restore Example1 date format
oclyke Jul 14, 2020
670d7fb
fix typo in Example1 restore
oclyke Jul 14, 2020
38d3a2a
Update RTC.cpp
adamgarbo Jul 15, 2020
a2279ed
Update RTC.h
adamgarbo Jul 15, 2020
2656e07
standardize RTC api for setTime and setAlarm
Jul 15, 2020
751ab8f
fix Example3
Jul 15, 2020
d3bd832
automatically update internal structures on setTime and setToCompiler…
Jul 16, 2020
0d0b549
Convert Example2 loop to non-blocking
Jul 16, 2020
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
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
/* Author: Nathan Seidle
/*
Author: Nathan Seidle
Created: Septempter 27th, 2019
License: MIT. See SparkFun Arduino Apollo3 Project for more information

This example demonstrates how to initialize and read from the on board RTC.
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 @@ -11,16 +13,19 @@
This example is based on the Ambiq SDK EVB2 RTC example.
*/

#include "RTC.h" //Include RTC library included with the Aruino_Apollo3 core
APM3_RTC myRTC; //Create instance of RTC class
#include "RTC.h" // Include RTC library included with the Aruino_Apollo3 core
APM3_RTC myRTC; // Create instance of RTC class

void setup()
{
Serial.begin(115200);
Serial.println("SparkFun RTC Example");

myRTC.setToCompilerTime(); //Easily set RTC using the system __DATE__ and __TIME__ macros from compiler
//myRTC.setTime(7, 28, 51, 0, 21, 10, 15); //Manually set RTC back to the future: Oct 21st, 2015 at 7:28.51 AM
// Easily set RTC using the system __DATE__ and __TIME__ macros from compiler
myRTC.setToCompilerTime();

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

void loop()
Expand Down

This file was deleted.

101 changes: 101 additions & 0 deletions libraries/RTC/examples/Example2_Set_Alarms/Example2_Set_Alarms.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/*
Author: Adam Garbo and Nathan Seidle
Created: June 3rd, 2020
License: MIT. See SparkFun Arduino Apollo3 Project for more information

This example demonstrates how to read and set the RTC alarms.

It is necessary to first set the RTC alarm date and time and then specify
the alarm mode, which determines which date and time values will be used
for comparison when generating an alarm interrupt.

The code is configured so that the RTC alarm will trigger every minute.
The RTC interrupt service routine will set an alarm flag each time the
alarm triggers and the RTC date and time will printed to the Serial Monitor.
*/

#include "RTC.h" // Include RTC library included with the Aruino_Apollo3 core
APM3_RTC myRTC; // Create instance of RTC class

volatile bool alarmFlag = false;

void setup()
{
Serial.begin(115200);
Serial.println("SparkFun RTC Set Alarm Example");

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

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

// Set the RTC's alarm
myRTC.setAlarm(13, 0, 0, 0, 3, 6); // 13:00:00.000, June 3rd (hund, ss, mm, hh, dd, mm). Note: No year alarm register
// Set the RTC alarm mode
/*
0: Alarm interrupt disabled
1: Alarm match every year (hundredths, seconds, minutes, hour, day, month)
2: Alarm match every month (hundredths, seconds, minutes, hours, day)
3: Alarm match every week (hundredths, seconds, minutes, hours, weekday)
4: Alarm match every day (hundredths, seconds, minute, hours)
5: Alarm match every hour (hundredths, seconds, minutes)
6: Alarm match every minute (hundredths, seconds)
7: Alarm match every second (hundredths)
*/
myRTC.setAlarmMode(6); // Set the RTC alarm to match on minutes rollover
myRTC.attachInterrupt(); // Attach RTC alarm interrupt

// Print the RTC's alarm date and time
Serial.print("Next alarm: "); printAlarm();
}

void loop()
{
// Check if alarm flag was set
if (alarmFlag == true)
{
// Print date and time of RTC alarm trigger
Serial.print("Alarm triggered: "); printDateTime();

// Clear alarm flag
alarmFlag = false;
}

// Print RTC's date and time while waiting for alarm
printDateTime();
delay(1000);
}

// Print the RTC's current date and time
void printDateTime()
{
myRTC.getTime();
char dateTimeBuffer[25];
sprintf(dateTimeBuffer, "20%02d-%02d-%02d %02d:%02d:%02d.%03d",
myRTC.year, myRTC.month, myRTC.dayOfMonth,
myRTC.hour, myRTC.minute, myRTC.seconds, myRTC.hundredths);
Serial.println(dateTimeBuffer);
}

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

// 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);

// Set alarm flag
alarmFlag = true;
}
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
/* Author: Nathan Seidle and stephenf7072
/*
Author: Nathan Seidle and stephenf7072
Created: January 28th, 2020
License: MIT. See SparkFun Arduino Apollo3 Project for more information

This example test the internal HAL to make sure the days advance correctly.
*/

#include "RTC.h"
APM3_RTC myRTC; //Create instance of RTC class
APM3_RTC myRTC; // Create instance of RTC class

int previousDay = 1;

void setup()
{
Serial.begin(115200);
delay(10);
Serial.println("Artemis RTC testing");
Serial.println("Artemis RTC Testing");

//myRTC.setTime(hh, mm, ss, hund, dd, mm, yy);
myRTC.setTime(23, 59, 59, 99, 1, 1, 19); //Manually set RTC to 1s before midnight
// Manually set RTC date and time
myRTC.setTime(23, 59, 59, 0, 1, 1, 20); // Set to 1 second before midnight
}

void loop()
{
printArtemisTime();

myRTC.getTime();
myRTC.setTime(23, 59, 59, 99, myRTC.dayOfMonth, myRTC.month, myRTC.year); //Manually set RTC
delay(11); //Allow us to roll from midnight the night before to the new day
myRTC.setTime(23, 59, 59, 99, myRTC.dayOfMonth, myRTC.month, myRTC.year); // Manually set RTC
delay(11); //Allow us to roll from midnight the night before to the new day
}

void printArtemisTime()
Expand Down Expand Up @@ -79,4 +80,4 @@ void printArtemisTime()
previousDay = myRTC.weekday;

Serial.println();
}
}
41 changes: 41 additions & 0 deletions libraries/RTC/examples/Example4_Set_Epoch/Example4_Set_Epoch.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
Author: Adam Garbo and Nathan Seidle
Created: June 3rd, 2020
License: MIT. See SparkFun Arduino Apollo3 Project for more information

This example demonstrates how to set the RTC using UNIX Epoch time.
*/

#include "RTC.h" // Include RTC library included with the Aruino_Apollo3 core
APM3_RTC myRTC; // Create instance of RTC class

void setup()
{
Serial.begin(115200);
Serial.println("SparkFun RTC Set UNIX Epoch Time Example");

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

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

// Print RTC's date and time
Serial.print("Timestamp: "); printDateTime();

delay(1000);
}

// Print the RTC's current date and time
void printDateTime()
{
myRTC.getTime();
char dateTime[20];
sprintf(dateTime, "20%02d-%02d-%02d %02d:%02d:%02d",
myRTC.year, myRTC.month, myRTC.dayOfMonth,
myRTC.hour, myRTC.minute, myRTC.seconds);
Serial.println(dateTime);
}
Loading