From b1d3cfa97c23c9ebacffc60dca2b8366e5732e0b Mon Sep 17 00:00:00 2001 From: Adam Date: Wed, 22 Apr 2020 15:09:57 -0400 Subject: [PATCH 01/51] Update RTC --- libraries/RTC/keywords.txt | 5 ++ libraries/RTC/library.properties | 2 +- libraries/RTC/src/RTC.cpp | 92 +++++++++++++++++++++++++++----- libraries/RTC/src/RTC.h | 7 +++ 4 files changed, 91 insertions(+), 15 deletions(-) diff --git a/libraries/RTC/keywords.txt b/libraries/RTC/keywords.txt index d6069c6e..8fc1cdfe 100644 --- a/libraries/RTC/keywords.txt +++ b/libraries/RTC/keywords.txt @@ -13,9 +13,14 @@ RTC KEYWORD1 ####################################### getTime KEYWORD2 +getEpoch KEYWORD2 setTime KEYWORD2 setTimeToCompiler KEYWORD2 +getAlarm KEYWORD2 +setAlarm KEYWORD2 +setAlarmMode KEYWORD2 + hour KEYWORD2 minute KEYWORD2 seconds KEYWORD2 diff --git a/libraries/RTC/library.properties b/libraries/RTC/library.properties index 0d9e581f..204d0812 100644 --- a/libraries/RTC/library.properties +++ b/libraries/RTC/library.properties @@ -1,5 +1,5 @@ name=RTC -version=1.0 +version=1.1 author=SparkFun Electronics maintainer=SparkFun Electronics sentence=Real Time Clock (RTC)) library for the SparkFun Artemis diff --git a/libraries/RTC/src/RTC.cpp b/libraries/RTC/src/RTC.cpp index f061809c..5766c2a0 100644 --- a/libraries/RTC/src/RTC.cpp +++ b/libraries/RTC/src/RTC.cpp @@ -3,6 +3,7 @@ */ #include "RTC.h" +#include am_hal_rtc_time_t hal_time; @@ -37,30 +38,28 @@ char const *pcMonth[] = //Constructor APM3_RTC::APM3_RTC() { - // Enable the XT for the RTC. + //Enable the XT for the RTC. am_hal_clkgen_control(AM_HAL_CLKGEN_CONTROL_XTAL_START, 0); - // Select XT for RTC clock source + //Select XT for RTC clock source am_hal_rtc_osc_select(AM_HAL_RTC_OSC_XT); - // Enable the RTC. + //Enable the RTC. am_hal_rtc_osc_enable(); } -void APM3_RTC::setTime(uint8_t hour, uint8_t min, uint8_t sec, uint8_t hund, uint8_t dayOfMonth, uint8_t month, uint16_t year) +void APM3_RTC::setTime(uint8_t hund, uint8_t sec, uint8_t min, uint8_t hour, uint8_t dayOfMonth, uint8_t month, uint16_t year) { + hal_time.ui32Weekday = am_util_time_computeDayofWeek(2000 + year, month, dayOfMonth); //computeDayofWeek is expecting 1 to 12 months + hal_time.ui32Century = 0; + hal_time.ui32Year = year; + hal_time.ui32Month = month; //HAL is expecting 1 to 12 months + hal_time.ui32DayOfMonth = dayOfMonth; hal_time.ui32Hour = hour; hal_time.ui32Minute = min; hal_time.ui32Second = sec; hal_time.ui32Hundredths = hund; - hal_time.ui32DayOfMonth = dayOfMonth; - hal_time.ui32Month = month; //HAL is expecting 1 to 12 months - hal_time.ui32Year = year; - hal_time.ui32Century = 0; - - hal_time.ui32Weekday = am_util_time_computeDayofWeek(2000 + year, month, dayOfMonth); //computeDayofWeek is expecting 1 to 12 months - am_hal_rtc_time_set(&hal_time); //Initialize the RTC with this date/time } @@ -87,17 +86,82 @@ void APM3_RTC::getTime() { am_hal_rtc_time_get(&hal_time); + weekday = hal_time.ui32Weekday; + textWeekday = pcWeekday[hal_time.ui32Weekday]; //Given a number (day of week) return the string that represents the name + year = hal_time.ui32Year; + dayOfMonth = hal_time.ui32DayOfMonth; + month = hal_time.ui32Month; //HAL outputs months in 1 to 12 form hour = hal_time.ui32Hour; minute = hal_time.ui32Minute; seconds = hal_time.ui32Second; hundredths = hal_time.ui32Hundredths; +} - month = hal_time.ui32Month; //HAL outputs months in 1 to 12 form - dayOfMonth = hal_time.ui32DayOfMonth; - year = hal_time.ui32Year; +uint32_t APM3_RTC::getEpoch() +{ + am_hal_rtc_time_get(&hal_time); + + struct tm tm; + + tm.tm_isdst = -1; + tm.tm_yday = 0; + tm.tm_wday = 0; + tm.tm_year = hal_time.ui32Year + 100; //Number of years since 1900. + tm.tm_mon = hal_time.ui32Month - 1; //mktime is expecting 0 to 11 months + tm.tm_mday = hal_time.ui32DayOfMonth; + tm.tm_hour = hal_time.ui32Hour; + tm.tm_min = hal_time.ui32Minute; + tm.tm_sec = hal_time.ui32Second; + return mktime(&tm); +} + +void APM3_RTC::getAlarm() +{ + am_hal_rtc_alarm_get(&alm_time); //Get the RTC's alarm time + weekday = hal_time.ui32Weekday; textWeekday = pcWeekday[hal_time.ui32Weekday]; //Given a number (day of week) return the string that represents the name + year = hal_time.ui32Year; + dayOfMonth = hal_time.ui32DayOfMonth; + month = hal_time.ui32Month; //HAL outputs months in 1 to 12 form + hour = hal_time.ui32Hour; + minute = hal_time.ui32Minute; + seconds = hal_time.ui32Second; + hundredths = hal_time.ui32Hundredths; +} + +void APM3_RTC::setAlarm(uint8_t hund, uint8_t min, uint8_t sec, uint8_t hour, uint8_t dayOfMonth, uint8_t month) +{ + hal_time.ui32Weekday = am_util_time_computeDayofWeek(2000 + year, month, dayOfMonth); //computeDayofWeek is expecting 1 to 12 months + hal_time.ui32Month = month; + hal_time.ui32DayOfMonth = dayOfMonth; + hal_time.ui32Hour = hour; + hal_time.ui32Minute = min; + hal_time.ui32Second = sec; + hal_time.ui32Hundredths = hund; + + am_hal_rtc_alarm_set(&alm_time, AM_HAL_RTC_ALM_RPT_DIS); //Initialize the RTC alarm with this date/time +} + +// Sets the RTC alarm repeat interval. +/* + RTC alarm repeat intervals + 0: Alarm interrupt disabled + 1: Interrupt every year + 2: Interrupt every month + 3: Interrupt every week + 4: Interrupt every day + 5: Interrupt every hour + 6: Interrupt every minute + 7: Interrupt every second/10th/100th + 8: AM_HAL_RTC_ALM_RPT_10TH + 9: AM_HAL_RTC_ALM_RPT_100TH +*/ +void APM3_RTC::setAlarmMode(uint8_t mode) +{ + am_hal_rtc_alarm_interval_set(mode); + } // mthToIndex() converts a string indicating a month to an index value. diff --git a/libraries/RTC/src/RTC.h b/libraries/RTC/src/RTC.h index a4262bce..a58bda1c 100644 --- a/libraries/RTC/src/RTC.h +++ b/libraries/RTC/src/RTC.h @@ -9,10 +9,17 @@ class APM3_RTC APM3_RTC(); void getTime(); //Query the RTC for the current time/date. Loads .seconds, .minute, etc. + void getEpoch(); //Return the current RTC time/date as UNIX Epoch time + void setTime(uint8_t hour, uint8_t min, uint8_t sec, uint8_t hund, uint8_t dayOfMonth, uint8_t month, uint16_t year); //Set current time to provided hundredths/seconds/etc void setToCompilerTime(); //Set to time when sketch was compiled + void getAlarm(); //Query the RTC for the current alarm time/date. + void setAlarm(uint8_t hour, uint8_t min, uint8_t sec, uint8_t hund, + uint8_t dayOfMonth, uint8_t month, uint16_t year); //Set alarm time to provided hundredths/seconds/etc + void setAlarmMode(); //Set the RTC alarm repeat interval + uint32_t hour; uint32_t minute; uint32_t seconds; From 0d7b0a3a51c15cf08aa5775b64dcbec953f4ace6 Mon Sep 17 00:00:00 2001 From: Adam Date: Thu, 23 Apr 2020 10:20:11 -0400 Subject: [PATCH 02/51] Update RTC.h --- libraries/RTC/src/RTC.h | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/libraries/RTC/src/RTC.h b/libraries/RTC/src/RTC.h index a58bda1c..b8a42132 100644 --- a/libraries/RTC/src/RTC.h +++ b/libraries/RTC/src/RTC.h @@ -9,16 +9,14 @@ class APM3_RTC APM3_RTC(); void getTime(); //Query the RTC for the current time/date. Loads .seconds, .minute, etc. - void getEpoch(); //Return the current RTC time/date as UNIX Epoch time + uint32_t getEpoch(); //Return the current RTC time/date as UNIX Epoch time - void setTime(uint8_t hour, uint8_t min, uint8_t sec, uint8_t hund, - uint8_t dayOfMonth, uint8_t month, uint16_t year); //Set current time to provided hundredths/seconds/etc - void setToCompilerTime(); //Set to time when sketch was compiled + void setTime(uint8_t hund, uint8_t sec, uint8_t min, uint8_t hour, uint8_t dayOfMonth, uint8_t month, uint16_t year); //Set current time to provided hundredths/seconds/etc + void setToCompilerTime(); //Set to time when sketch was compiled void getAlarm(); //Query the RTC for the current alarm time/date. - void setAlarm(uint8_t hour, uint8_t min, uint8_t sec, uint8_t hund, - uint8_t dayOfMonth, uint8_t month, uint16_t year); //Set alarm time to provided hundredths/seconds/etc - void setAlarmMode(); //Set the RTC alarm repeat interval + void setAlarm(uint8_t hund, uint8_t min, uint8_t sec, uint8_t hour, uint8_t dayOfMonth, uint8_t month); //Set alarm time to provided hundredths/seconds/etc + void setAlarmMode(uint8_t mode); //Set the RTC alarm repeat interval uint32_t hour; uint32_t minute; From ada4050036e3cae659469604f544cf4ff63247c7 Mon Sep 17 00:00:00 2001 From: Adam Date: Thu, 23 Apr 2020 10:20:14 -0400 Subject: [PATCH 03/51] Update RTC.cpp --- libraries/RTC/src/RTC.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libraries/RTC/src/RTC.cpp b/libraries/RTC/src/RTC.cpp index 5766c2a0..f5a19c04 100644 --- a/libraries/RTC/src/RTC.cpp +++ b/libraries/RTC/src/RTC.cpp @@ -6,6 +6,7 @@ #include am_hal_rtc_time_t hal_time; +am_hal_rtc_time_t alm_time; // String arrays to index Days and Months with the values returned by the RTC. char const *pcWeekday[] = @@ -133,7 +134,6 @@ void APM3_RTC::getAlarm() void APM3_RTC::setAlarm(uint8_t hund, uint8_t min, uint8_t sec, uint8_t hour, uint8_t dayOfMonth, uint8_t month) { - hal_time.ui32Weekday = am_util_time_computeDayofWeek(2000 + year, month, dayOfMonth); //computeDayofWeek is expecting 1 to 12 months hal_time.ui32Month = month; hal_time.ui32DayOfMonth = dayOfMonth; hal_time.ui32Hour = hour; @@ -161,7 +161,6 @@ void APM3_RTC::setAlarm(uint8_t hund, uint8_t min, uint8_t sec, uint8_t hour, ui void APM3_RTC::setAlarmMode(uint8_t mode) { am_hal_rtc_alarm_interval_set(mode); - } // mthToIndex() converts a string indicating a month to an index value. From ad336ad62d4ff90c94343082fb43e1f28d280763 Mon Sep 17 00:00:00 2001 From: Adam Date: Thu, 23 Apr 2020 13:52:41 -0400 Subject: [PATCH 04/51] Update RTC.h --- libraries/RTC/src/RTC.h | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/libraries/RTC/src/RTC.h b/libraries/RTC/src/RTC.h index b8a42132..c443e8f1 100644 --- a/libraries/RTC/src/RTC.h +++ b/libraries/RTC/src/RTC.h @@ -18,19 +18,26 @@ class APM3_RTC void setAlarm(uint8_t hund, uint8_t min, uint8_t sec, uint8_t hour, uint8_t dayOfMonth, uint8_t month); //Set alarm time to provided hundredths/seconds/etc void setAlarmMode(uint8_t mode); //Set the RTC alarm repeat interval + uint32_t weekday; //0 to 6 representing the day of the week + uint32_t century; + uint32_t year; + uint32_t month; + uint32_t dayOfMonth; uint32_t hour; uint32_t minute; uint32_t seconds; uint32_t hundredths; - - uint32_t dayOfMonth; - uint32_t month; - uint32_t year; - uint32_t century; - - uint32_t weekday; //0 to 6 representing the day of the week const char *textWeekday; + uint32_t alarmWeekday; //0 to 6 representing the day of the week + uint32_t alarmMonth; + uint32_t alarmDayOfMonth; + uint32_t alarmHour; + uint32_t alarmMinute; + uint32_t alarmSeconds; + uint32_t alarmHundredths; + const char *alarmTextWeekday; + private: //Helper functions to convert compiler date/time to ints int toVal(char const *pcAsciiStr); From ba5c8162663cc55792bf1b8b6f4cb5d2f17f7be5 Mon Sep 17 00:00:00 2001 From: Adam Date: Thu, 23 Apr 2020 13:52:43 -0400 Subject: [PATCH 05/51] Update RTC.cpp --- libraries/RTC/src/RTC.cpp | 47 +++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/libraries/RTC/src/RTC.cpp b/libraries/RTC/src/RTC.cpp index f5a19c04..e0378b49 100644 --- a/libraries/RTC/src/RTC.cpp +++ b/libraries/RTC/src/RTC.cpp @@ -70,15 +70,15 @@ void APM3_RTC::setToCompilerTime() { //Get the current date/time from the compiler //Alternatively, you can set these values manually + hal_time.ui32Weekday = am_util_time_computeDayofWeek(2000 + toVal(&__DATE__[9]), mthToIndex(&__DATE__[0]) + 1, toVal(&__DATE__[4])); + hal_time.ui32Century = 0; + hal_time.ui32Year = toVal(&__DATE__[9]); + hal_time.ui32Month = mthToIndex(&__DATE__[0]) + 1; //Compiler ouputs months in 0-11. + hal_time.ui32DayOfMonth = toVal(&__DATE__[4]); hal_time.ui32Hour = toVal(&__TIME__[0]); hal_time.ui32Minute = toVal(&__TIME__[3]); hal_time.ui32Second = toVal(&__TIME__[6]); hal_time.ui32Hundredths = 00; - hal_time.ui32Weekday = am_util_time_computeDayofWeek(2000 + toVal(&__DATE__[9]), mthToIndex(&__DATE__[0]) + 1, toVal(&__DATE__[4])); - hal_time.ui32DayOfMonth = toVal(&__DATE__[4]); - hal_time.ui32Month = mthToIndex(&__DATE__[0]) + 1; //Compiler ouputs months in 0-11. - hal_time.ui32Year = toVal(&__DATE__[9]); - hal_time.ui32Century = 0; am_hal_rtc_time_set(&hal_time); //Initialize the RTC with this date/time } @@ -90,8 +90,8 @@ void APM3_RTC::getTime() weekday = hal_time.ui32Weekday; textWeekday = pcWeekday[hal_time.ui32Weekday]; //Given a number (day of week) return the string that represents the name year = hal_time.ui32Year; - dayOfMonth = hal_time.ui32DayOfMonth; month = hal_time.ui32Month; //HAL outputs months in 1 to 12 form + dayOfMonth = hal_time.ui32DayOfMonth; hour = hal_time.ui32Hour; minute = hal_time.ui32Minute; seconds = hal_time.ui32Second; @@ -121,25 +121,24 @@ void APM3_RTC::getAlarm() { am_hal_rtc_alarm_get(&alm_time); //Get the RTC's alarm time - weekday = hal_time.ui32Weekday; - textWeekday = pcWeekday[hal_time.ui32Weekday]; //Given a number (day of week) return the string that represents the name - year = hal_time.ui32Year; - dayOfMonth = hal_time.ui32DayOfMonth; - month = hal_time.ui32Month; //HAL outputs months in 1 to 12 form - hour = hal_time.ui32Hour; - minute = hal_time.ui32Minute; - seconds = hal_time.ui32Second; - hundredths = hal_time.ui32Hundredths; + alarmWeekday = alm_time.ui32Weekday; + alarmMonth = alm_time.ui32Month; //HAL outputs months in 1 to 12 form + alarmDayOfMonth = alm_time.ui32DayOfMonth; + alarmHour = alm_time.ui32Hour; + alarmMinute = alm_time.ui32Minute; + alarmSeconds = alm_time.ui32Second; + alarmHundredths = alm_time.ui32Hundredths; + } - -void APM3_RTC::setAlarm(uint8_t hund, uint8_t min, uint8_t sec, uint8_t hour, uint8_t dayOfMonth, uint8_t month) + +void APM3_RTC::setAlarm(uint8_t hund, uint8_t sec, uint8_t min, uint8_t hour, uint8_t dayOfMonth, uint8_t month) { - hal_time.ui32Month = month; - hal_time.ui32DayOfMonth = dayOfMonth; - hal_time.ui32Hour = hour; - hal_time.ui32Minute = min; - hal_time.ui32Second = sec; - hal_time.ui32Hundredths = hund; + alm_time.ui32Month = month; + alm_time.ui32DayOfMonth = dayOfMonth; + alm_time.ui32Hour = hour; + alm_time.ui32Minute = min; + alm_time.ui32Second = sec; + alm_time.ui32Hundredths = hund; am_hal_rtc_alarm_set(&alm_time, AM_HAL_RTC_ALM_RPT_DIS); //Initialize the RTC alarm with this date/time } @@ -160,7 +159,7 @@ void APM3_RTC::setAlarm(uint8_t hund, uint8_t min, uint8_t sec, uint8_t hour, ui */ void APM3_RTC::setAlarmMode(uint8_t mode) { - am_hal_rtc_alarm_interval_set(mode); + //am_hal_rtc_alarm_interval_set(mode); } // mthToIndex() converts a string indicating a month to an index value. From d10ee3f87c6852d8a5ad577ffbd65217f0e2b72e Mon Sep 17 00:00:00 2001 From: Adam Date: Thu, 23 Apr 2020 13:52:48 -0400 Subject: [PATCH 06/51] Update keywords.txt --- libraries/RTC/keywords.txt | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/libraries/RTC/keywords.txt b/libraries/RTC/keywords.txt index 8fc1cdfe..e3539ea8 100644 --- a/libraries/RTC/keywords.txt +++ b/libraries/RTC/keywords.txt @@ -32,6 +32,15 @@ year KEYWORD2 weekday KEYWORD2 textWeekday KEYWORD2 +alarmWeekday KEYWORD2 +alarmMonth KEYWORD2 +alarmDayOfMonth KEYWORD2 +alarmHour KEYWORD2 +alarmMinute KEYWORD2 +alarmSeconds KEYWORD2 +alarmHundredths KEYWORD2 +alarmTextWeekday KEYWORD2 + ####################################### # Constants (LITERAL1) ####################################### From 17ca26f201826f11c7736e94287f9029e2e8be01 Mon Sep 17 00:00:00 2001 From: Adam Date: Thu, 23 Apr 2020 13:57:04 -0400 Subject: [PATCH 07/51] Update RTC.cpp --- libraries/RTC/src/RTC.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libraries/RTC/src/RTC.cpp b/libraries/RTC/src/RTC.cpp index e0378b49..bb71fb0b 100644 --- a/libraries/RTC/src/RTC.cpp +++ b/libraries/RTC/src/RTC.cpp @@ -127,8 +127,7 @@ void APM3_RTC::getAlarm() alarmHour = alm_time.ui32Hour; alarmMinute = alm_time.ui32Minute; alarmSeconds = alm_time.ui32Second; - alarmHundredths = alm_time.ui32Hundredths; - + alarmHundredths = alm_time.ui32Hundredths; } void APM3_RTC::setAlarm(uint8_t hund, uint8_t sec, uint8_t min, uint8_t hour, uint8_t dayOfMonth, uint8_t month) From bf780abe7d9c9ae946778c0946aa51c8caf04795 Mon Sep 17 00:00:00 2001 From: Adam Date: Thu, 23 Apr 2020 18:08:40 -0400 Subject: [PATCH 08/51] Update RTC.cpp --- libraries/RTC/src/RTC.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/RTC/src/RTC.cpp b/libraries/RTC/src/RTC.cpp index e0378b49..bfb4d7b9 100644 --- a/libraries/RTC/src/RTC.cpp +++ b/libraries/RTC/src/RTC.cpp @@ -127,7 +127,7 @@ void APM3_RTC::getAlarm() alarmHour = alm_time.ui32Hour; alarmMinute = alm_time.ui32Minute; alarmSeconds = alm_time.ui32Second; - alarmHundredths = alm_time.ui32Hundredths; + alarmHundredths = alm_time.ui32Hundredths; } @@ -159,7 +159,7 @@ void APM3_RTC::setAlarm(uint8_t hund, uint8_t sec, uint8_t min, uint8_t hour, ui */ void APM3_RTC::setAlarmMode(uint8_t mode) { - //am_hal_rtc_alarm_interval_set(mode); + am_hal_rtc_alarm_interval_set(mode); } // mthToIndex() converts a string indicating a month to an index value. From f4d55d13942096bf7fc12ddd5ae50687b132d89a Mon Sep 17 00:00:00 2001 From: Adam Date: Thu, 23 Apr 2020 18:08:43 -0400 Subject: [PATCH 09/51] Update keywords.txt --- libraries/RTC/keywords.txt | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/libraries/RTC/keywords.txt b/libraries/RTC/keywords.txt index e3539ea8..4b85821a 100644 --- a/libraries/RTC/keywords.txt +++ b/libraries/RTC/keywords.txt @@ -21,17 +21,16 @@ getAlarm KEYWORD2 setAlarm KEYWORD2 setAlarmMode KEYWORD2 +weekday KEYWORD2 +textWeekday KEYWORD2 +year KEYWORD2 +month KEYWORD2 +dayOfMonth KEYWORD2 hour KEYWORD2 minute KEYWORD2 seconds KEYWORD2 hundredths KEYWORD2 -month KEYWORD2 -dayOfMonth KEYWORD2 -year KEYWORD2 -weekday KEYWORD2 -textWeekday KEYWORD2 - alarmWeekday KEYWORD2 alarmMonth KEYWORD2 alarmDayOfMonth KEYWORD2 From 18c1e6fb80bc4357ada47dd6e9b51f36a135200d Mon Sep 17 00:00:00 2001 From: Adam Date: Fri, 24 Apr 2020 09:18:32 -0400 Subject: [PATCH 10/51] Update RTC.h --- libraries/RTC/src/RTC.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libraries/RTC/src/RTC.h b/libraries/RTC/src/RTC.h index c443e8f1..20e55668 100644 --- a/libraries/RTC/src/RTC.h +++ b/libraries/RTC/src/RTC.h @@ -13,10 +13,14 @@ class APM3_RTC void setTime(uint8_t hund, uint8_t sec, uint8_t min, uint8_t hour, uint8_t dayOfMonth, uint8_t month, uint16_t year); //Set current time to provided hundredths/seconds/etc void setToCompilerTime(); //Set to time when sketch was compiled + void setEpoch(uint32_t ts); //Set RTC date time with provided UNIX Epoch time void getAlarm(); //Query the RTC for the current alarm time/date. + uint32_t getAlarmEpoch(); //Return the current RTC alarm time/date as UNIX Epoch time void setAlarm(uint8_t hund, uint8_t min, uint8_t sec, uint8_t hour, uint8_t dayOfMonth, uint8_t month); //Set alarm time to provided hundredths/seconds/etc void setAlarmMode(uint8_t mode); //Set the RTC alarm repeat interval + void attachInterrupt(); //Attach RTC alarm interrupt + void detachInterrupt(); //Detach RTC alarm interrupt uint32_t weekday; //0 to 6 representing the day of the week uint32_t century; From 0043bf37f0ddaa0572c320e9053914619bb7ec4f Mon Sep 17 00:00:00 2001 From: Adam Date: Fri, 24 Apr 2020 09:18:35 -0400 Subject: [PATCH 11/51] Update RTC.cpp --- libraries/RTC/src/RTC.cpp | 94 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 93 insertions(+), 1 deletion(-) diff --git a/libraries/RTC/src/RTC.cpp b/libraries/RTC/src/RTC.cpp index bfb4d7b9..2695d774 100644 --- a/libraries/RTC/src/RTC.cpp +++ b/libraries/RTC/src/RTC.cpp @@ -8,7 +8,9 @@ am_hal_rtc_time_t hal_time; am_hal_rtc_time_t alm_time; -// String arrays to index Days and Months with the values returned by the RTC. +#define EPOCH_TIME 946684800 // UNIX Epoch time = 2000-01-01 00:00:00 + +//String arrays to index Days and Months with the values returned by the RTC. char const *pcWeekday[] = { "Sunday", @@ -83,6 +85,29 @@ void APM3_RTC::setToCompilerTime() am_hal_rtc_time_set(&hal_time); //Initialize the RTC with this date/time } +void APM3_RTC::setEpoch(uint32_t ts) +{ + if (ts < EPOCH_TIME) { + ts = EPOCH_TIME; + } + + struct tm tm; + + time_t t = ts; + struct tm* tmp = gmtime(&t); + hal_time.ui32Weekday = 0; + hal_time.ui32Century = 0; + hal_time.ui32Year = tmp->tm_year - 100; + hal_time.ui32Month = tmp->tm_mon + 1; + hal_time.ui32DayOfMonth = tmp->tm_mday; + hal_time.ui32Hour = tmp->tm_hour; + hal_time.ui32Minute = tmp->tm_min; + hal_time.ui32Second = tmp->tm_sec; + hal_time.ui32Hundredths = 0; + + am_hal_rtc_time_set(&hal_time); //Initialize the RTC with this date/time +} + void APM3_RTC::getTime() { am_hal_rtc_time_get(&hal_time); @@ -128,7 +153,25 @@ void APM3_RTC::getAlarm() alarmMinute = alm_time.ui32Minute; alarmSeconds = alm_time.ui32Second; alarmHundredths = alm_time.ui32Hundredths; +} + +uint32_t APM3_RTC::getAlarmEpoch() +{ + am_hal_rtc_alarm_get(&alm_time); //Get the RTC's alarm time + + struct tm tm; + tm.tm_isdst = -1; + tm.tm_yday = 0; + tm.tm_wday = 0; + tm.tm_year = alm_time.ui32Year + 100; //Number of years since 1900. + tm.tm_mon = alm_time.ui32Month - 1; //mktime is expecting 0 to 11 months + tm.tm_mday = alm_time.ui32DayOfMonth; + tm.tm_hour = alm_time.ui32Hour; + tm.tm_min = alm_time.ui32Minute; + tm.tm_sec = alm_time.ui32Second; + + return mktime(&tm); } void APM3_RTC::setAlarm(uint8_t hund, uint8_t sec, uint8_t min, uint8_t hour, uint8_t dayOfMonth, uint8_t month) @@ -143,6 +186,29 @@ void APM3_RTC::setAlarm(uint8_t hund, uint8_t sec, uint8_t min, uint8_t hour, ui am_hal_rtc_alarm_set(&alm_time, AM_HAL_RTC_ALM_RPT_DIS); //Initialize the RTC alarm with this date/time } +void APM3_RTC::setAlarmEpoch(uint32_t ts) +{ + if (ts < EPOCH_TIME) { + ts = EPOCH_TIME; + } + + struct tm tm; + + time_t t = ts; + struct tm* tmp = gmtime(&t); + alm_time.ui32Weekday = 0; + alm_time.ui32Century = 0; + alm_time.ui32Year = tmp->tm_year - 100; + alm_time.ui32Month = tmp->tm_mon + 1; + alm_time.ui32DayOfMonth = tmp->tm_mday; + alm_time.ui32Hour = tmp->tm_hour; + alm_time.ui32Minute = tmp->tm_min; + alm_time.ui32Second = tmp->tm_sec; + alm_time.ui32Hundredths = 0; + + am_hal_rtc_alarm_set(&alm_time, AM_HAL_RTC_ALM_RPT_DIS); //Initialize the RTC alarm with this date/time +} + // Sets the RTC alarm repeat interval. /* RTC alarm repeat intervals @@ -162,6 +228,32 @@ void APM3_RTC::setAlarmMode(uint8_t mode) am_hal_rtc_alarm_interval_set(mode); } + +void APM3_RTC::attachInterrupt() +{ + //Clear the RTC interrupt. + am_hal_rtc_int_clear(AM_HAL_RTC_INT_ALM); + + //Enable RTC interrupts to the NVIC. + NVIC_EnableIRQ(RTC_IRQn); + + //Enable interrupt signals from the NVIC to trigger ISR entry in the CPU. (Redundant?) + am_hal_interrupt_master_enable(); +} + +void APM3_RTC::detachInterrupt() +{ + //Clear the RTC interrupt. + am_hal_rtc_int_clear(AM_HAL_RTC_INT_ALM); + + //Disable interrupt signals from the NVIC to trigger ISR entry in the CPU. (Redundant?) + am_hal_interrupt_master_disable(); + + // Disable RTC interrupts to the NVIC. + NVIC_DisableIRQ(RTC_IRQn); +} + + // mthToIndex() converts a string indicating a month to an index value. // The return value is a value 0-12, with 0-11 indicating the month given // by the string, and 12 indicating that the string is not a month. From f3d9c7e7216a5e36661014f2f24bcac7008e68d7 Mon Sep 17 00:00:00 2001 From: Adam Date: Fri, 24 Apr 2020 09:18:38 -0400 Subject: [PATCH 12/51] Update keywords.txt --- libraries/RTC/keywords.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libraries/RTC/keywords.txt b/libraries/RTC/keywords.txt index 4b85821a..763dd960 100644 --- a/libraries/RTC/keywords.txt +++ b/libraries/RTC/keywords.txt @@ -14,12 +14,17 @@ RTC KEYWORD1 getTime KEYWORD2 getEpoch KEYWORD2 + setTime KEYWORD2 setTimeToCompiler KEYWORD2 +setEpoch KEYWORD2 getAlarm KEYWORD2 +getAlarmEpoch KEYWORD2 setAlarm KEYWORD2 setAlarmMode KEYWORD2 +attachInterrupt KEYWORD2 +detachInterrupt KEYWORD2 weekday KEYWORD2 textWeekday KEYWORD2 From da71acbcc4bdc7a070756428dea7aa168b4b3480 Mon Sep 17 00:00:00 2001 From: Adam Date: Fri, 24 Apr 2020 12:41:47 -0400 Subject: [PATCH 13/51] Update RTC.h --- libraries/RTC/src/RTC.h | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/libraries/RTC/src/RTC.h b/libraries/RTC/src/RTC.h index 20e55668..033608a4 100644 --- a/libraries/RTC/src/RTC.h +++ b/libraries/RTC/src/RTC.h @@ -8,19 +8,18 @@ class APM3_RTC public: APM3_RTC(); - void getTime(); //Query the RTC for the current time/date. Loads .seconds, .minute, etc. + void getTime(); //Query the RTC for the current time/date uint32_t getEpoch(); //Return the current RTC time/date as UNIX Epoch time void setTime(uint8_t hund, uint8_t sec, uint8_t min, uint8_t hour, uint8_t dayOfMonth, uint8_t month, uint16_t year); //Set current time to provided hundredths/seconds/etc void setToCompilerTime(); //Set to time when sketch was compiled - void setEpoch(uint32_t ts); //Set RTC date time with provided UNIX Epoch time + void setEpoch(uint32_t ts); //Set current time to provided UNIX Epoch time - void getAlarm(); //Query the RTC for the current alarm time/date. - uint32_t getAlarmEpoch(); //Return the current RTC alarm time/date as UNIX Epoch time + void getAlarm(); //Query the RTC for the current alarm time/date void setAlarm(uint8_t hund, uint8_t min, uint8_t sec, uint8_t hour, uint8_t dayOfMonth, uint8_t month); //Set alarm time to provided hundredths/seconds/etc void setAlarmMode(uint8_t mode); //Set the RTC alarm repeat interval - void attachInterrupt(); //Attach RTC alarm interrupt - void detachInterrupt(); //Detach RTC alarm interrupt + void attachInterrupt(); //Attach the RTC alarm interrupt + void detachInterrupt(); //Detach the RTC alarm interrupt uint32_t weekday; //0 to 6 representing the day of the week uint32_t century; From cd53b25f604b1d69988c7f9e0c7912b2e1cb48af Mon Sep 17 00:00:00 2001 From: Adam Date: Fri, 24 Apr 2020 12:41:52 -0400 Subject: [PATCH 14/51] Update keywords.txt --- libraries/RTC/keywords.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/libraries/RTC/keywords.txt b/libraries/RTC/keywords.txt index 763dd960..6b719deb 100644 --- a/libraries/RTC/keywords.txt +++ b/libraries/RTC/keywords.txt @@ -20,7 +20,6 @@ setTimeToCompiler KEYWORD2 setEpoch KEYWORD2 getAlarm KEYWORD2 -getAlarmEpoch KEYWORD2 setAlarm KEYWORD2 setAlarmMode KEYWORD2 attachInterrupt KEYWORD2 From 493200c536c662d969bd07d1bf4d3fb7b117e7f3 Mon Sep 17 00:00:00 2001 From: Adam Date: Fri, 24 Apr 2020 12:41:58 -0400 Subject: [PATCH 15/51] Update RTC.cpp --- libraries/RTC/src/RTC.cpp | 87 +++++++++++---------------------------- 1 file changed, 24 insertions(+), 63 deletions(-) diff --git a/libraries/RTC/src/RTC.cpp b/libraries/RTC/src/RTC.cpp index 2695d774..105f688c 100644 --- a/libraries/RTC/src/RTC.cpp +++ b/libraries/RTC/src/RTC.cpp @@ -155,27 +155,9 @@ void APM3_RTC::getAlarm() alarmHundredths = alm_time.ui32Hundredths; } -uint32_t APM3_RTC::getAlarmEpoch() -{ - am_hal_rtc_alarm_get(&alm_time); //Get the RTC's alarm time - - struct tm tm; - - tm.tm_isdst = -1; - tm.tm_yday = 0; - tm.tm_wday = 0; - tm.tm_year = alm_time.ui32Year + 100; //Number of years since 1900. - tm.tm_mon = alm_time.ui32Month - 1; //mktime is expecting 0 to 11 months - tm.tm_mday = alm_time.ui32DayOfMonth; - tm.tm_hour = alm_time.ui32Hour; - tm.tm_min = alm_time.ui32Minute; - tm.tm_sec = alm_time.ui32Second; - - return mktime(&tm); -} - void APM3_RTC::setAlarm(uint8_t hund, uint8_t sec, uint8_t min, uint8_t hour, uint8_t dayOfMonth, uint8_t month) { + alm_time.ui32Weekday = 0; // WIP alm_time.ui32Month = month; alm_time.ui32DayOfMonth = dayOfMonth; alm_time.ui32Hour = hour; @@ -186,73 +168,52 @@ void APM3_RTC::setAlarm(uint8_t hund, uint8_t sec, uint8_t min, uint8_t hour, ui am_hal_rtc_alarm_set(&alm_time, AM_HAL_RTC_ALM_RPT_DIS); //Initialize the RTC alarm with this date/time } -void APM3_RTC::setAlarmEpoch(uint32_t ts) -{ - if (ts < EPOCH_TIME) { - ts = EPOCH_TIME; - } - - struct tm tm; - - time_t t = ts; - struct tm* tmp = gmtime(&t); - alm_time.ui32Weekday = 0; - alm_time.ui32Century = 0; - alm_time.ui32Year = tmp->tm_year - 100; - alm_time.ui32Month = tmp->tm_mon + 1; - alm_time.ui32DayOfMonth = tmp->tm_mday; - alm_time.ui32Hour = tmp->tm_hour; - alm_time.ui32Minute = tmp->tm_min; - alm_time.ui32Second = tmp->tm_sec; - alm_time.ui32Hundredths = 0; - - am_hal_rtc_alarm_set(&alm_time, AM_HAL_RTC_ALM_RPT_DIS); //Initialize the RTC alarm with this date/time -} - // Sets the RTC alarm repeat interval. /* RTC alarm repeat intervals - 0: Alarm interrupt disabled - 1: Interrupt every year - 2: Interrupt every month - 3: Interrupt every week - 4: Interrupt every day - 5: Interrupt every hour - 6: Interrupt every minute - 7: Interrupt every second/10th/100th - 8: AM_HAL_RTC_ALM_RPT_10TH - 9: AM_HAL_RTC_ALM_RPT_100TH + 0: AM_HAL_RTC_ALM_RPT_DIS Alarm interrupt disabled + 1: AM_HAL_RTC_ALM_RPT_YR Interrupt every year + 2: AM_HAL_RTC_ALM_RPT_MTH Interrupt every month + 3: AM_HAL_RTC_ALM_RPT_WK Interrupt every week + 4: AM_HAL_RTC_ALM_RPT_DAY Interrupt every day + 5: AM_HAL_RTC_ALM_RPT_HR Interrupt every hour + 6: AM_HAL_RTC_ALM_RPT_MIN Interrupt every minute + 7: AM_HAL_RTC_ALM_RPT_SEC Interrupt every second + 8: AM_HAL_RTC_ALM_RPT_10TH Interrupt every 10th second + 9: AM_HAL_RTC_ALM_RPT_100TH Interrupt every 100th second */ void APM3_RTC::setAlarmMode(uint8_t mode) { am_hal_rtc_alarm_interval_set(mode); } - void APM3_RTC::attachInterrupt() { - //Clear the RTC interrupt. + // Enable the RTC interrupt. + am_hal_rtc_int_enable(AM_HAL_RTC_INT_ALM); + + // Clear the RTC interrupt. am_hal_rtc_int_clear(AM_HAL_RTC_INT_ALM); - //Enable RTC interrupts to the NVIC. + // Enable RTC interrupts to the NVIC. NVIC_EnableIRQ(RTC_IRQn); - //Enable interrupt signals from the NVIC to trigger ISR entry in the CPU. (Redundant?) - am_hal_interrupt_master_enable(); + // Enable interrupt signals from the NVIC to trigger ISR entry in the CPU. (Redundant?) + //am_hal_interrupt_master_enable(); + } void APM3_RTC::detachInterrupt() { - //Clear the RTC interrupt. - am_hal_rtc_int_clear(AM_HAL_RTC_INT_ALM); - - //Disable interrupt signals from the NVIC to trigger ISR entry in the CPU. (Redundant?) - am_hal_interrupt_master_disable(); + // Disable interrupt signals from the NVIC to trigger ISR entry in the CPU. (Redundant?) + // am_hal_interrupt_master_disable(); // Disable RTC interrupts to the NVIC. NVIC_DisableIRQ(RTC_IRQn); -} + // Disable the RTC interrupt. + am_hal_rtc_int_disable(AM_HAL_RTC_INT_ALM); +} // mthToIndex() converts a string indicating a month to an index value. // The return value is a value 0-12, with 0-11 indicating the month given From 5fa9db4ecc307348a57099d804113174428db8a9 Mon Sep 17 00:00:00 2001 From: Adam Date: Sat, 25 Apr 2020 13:23:20 -0400 Subject: [PATCH 16/51] Update Example3_TestRTC.ino --- .../RTC/examples/Example3_TestRTC/Example3_TestRTC.ino | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/libraries/RTC/examples/Example3_TestRTC/Example3_TestRTC.ino b/libraries/RTC/examples/Example3_TestRTC/Example3_TestRTC.ino index ba5fdcca..6fb970b0 100644 --- a/libraries/RTC/examples/Example3_TestRTC/Example3_TestRTC.ino +++ b/libraries/RTC/examples/Example3_TestRTC/Example3_TestRTC.ino @@ -6,7 +6,7 @@ */ #include "RTC.h" -APM3_RTC myRTC; //Create instance of RTC class +APM3_RTC myRTC; // Create instance of RTC class int previousDay = 1; @@ -16,8 +16,8 @@ void setup() delay(10); 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 + //myRTC.setTime(hund, ss, mm, hh, dd, mm, yy); + myRTC.setTime(0, 59, 59, 23, 1, 1, 20); // Manually set RTC to 1s before midnight } void loop() @@ -25,7 +25,7 @@ void loop() printArtemisTime(); myRTC.getTime(); - myRTC.setTime(23, 59, 59, 99, myRTC.dayOfMonth, myRTC.month, myRTC.year); //Manually set RTC + myRTC.setTime(99, 59, 59, 23, myRTC.dayOfMonth, myRTC.month, myRTC.year); //Manually set RTC delay(11); //Allow us to roll from midnight the night before to the new day } @@ -79,4 +79,4 @@ void printArtemisTime() previousDay = myRTC.weekday; Serial.println(); -} \ No newline at end of file +} From 28504be3e103a907443afe79539787a77ae0fb93 Mon Sep 17 00:00:00 2001 From: Adam Date: Sat, 25 Apr 2020 13:23:23 -0400 Subject: [PATCH 17/51] Update Example2_RTCwithSleep.ino --- .../examples/Example2_RTCwithSleep/Example2_RTCwithSleep.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/RTC/examples/Example2_RTCwithSleep/Example2_RTCwithSleep.ino b/libraries/RTC/examples/Example2_RTCwithSleep/Example2_RTCwithSleep.ino index 0103a64c..32c75dc7 100644 --- a/libraries/RTC/examples/Example2_RTCwithSleep/Example2_RTCwithSleep.ino +++ b/libraries/RTC/examples/Example2_RTCwithSleep/Example2_RTCwithSleep.ino @@ -20,7 +20,7 @@ void setup() 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 + //myRTC.setTime(0, 51, 28, 7, 21, 10, 15); //Manually set RTC back to the future: Oct 21st, 2015 at 7:28.51 AM setupWakeTimer(); } From ab7447d0ba17b2f7f64caf0baa5312374ad5dc70 Mon Sep 17 00:00:00 2001 From: Adam Date: Sat, 25 Apr 2020 13:23:25 -0400 Subject: [PATCH 18/51] Update Example1_getTime.ino --- libraries/RTC/examples/Example1_getTime/Example1_getTime.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/RTC/examples/Example1_getTime/Example1_getTime.ino b/libraries/RTC/examples/Example1_getTime/Example1_getTime.ino index 766daaac..e6d6611e 100644 --- a/libraries/RTC/examples/Example1_getTime/Example1_getTime.ino +++ b/libraries/RTC/examples/Example1_getTime/Example1_getTime.ino @@ -20,7 +20,7 @@ void setup() 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 + //myRTC.setTime(0, 51, 28, 7, 21, 10, 15); //Manually set RTC back to the future: Oct 21st, 2015 at 7:28.51 AM } void loop() From 69cc615cabf83a6ec040c1bf5d4ea76aff0ea564 Mon Sep 17 00:00:00 2001 From: Adam Date: Sat, 23 May 2020 14:11:35 -0400 Subject: [PATCH 19/51] Update RTC.h --- libraries/RTC/src/RTC.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/RTC/src/RTC.h b/libraries/RTC/src/RTC.h index 033608a4..7e3e2305 100644 --- a/libraries/RTC/src/RTC.h +++ b/libraries/RTC/src/RTC.h @@ -16,7 +16,7 @@ class APM3_RTC void setEpoch(uint32_t ts); //Set current time to provided UNIX Epoch time void getAlarm(); //Query the RTC for the current alarm time/date - void setAlarm(uint8_t hund, uint8_t min, uint8_t sec, uint8_t hour, uint8_t dayOfMonth, uint8_t month); //Set alarm time to provided hundredths/seconds/etc + void setAlarm(uint8_t hund, uint8_t sec, uint8_t min, uint8_t hour, uint8_t dayOfMonth, uint8_t month); //Set alarm time to provided hundredths/seconds/etc void setAlarmMode(uint8_t mode); //Set the RTC alarm repeat interval void attachInterrupt(); //Attach the RTC alarm interrupt void detachInterrupt(); //Detach the RTC alarm interrupt From 6ae120850cebcbdad4ac0aa2e2f3ecfbd0fa5100 Mon Sep 17 00:00:00 2001 From: Adam Date: Sat, 23 May 2020 15:12:04 -0400 Subject: [PATCH 20/51] Create Example1_Get_Time.ino --- .../Example1_Get_Time/Example1_Get_Time.ino | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 libraries/RTC/examples/Example1_Get_Time/Example1_Get_Time.ino diff --git a/libraries/RTC/examples/Example1_Get_Time/Example1_Get_Time.ino b/libraries/RTC/examples/Example1_Get_Time/Example1_Get_Time.ino new file mode 100644 index 00000000..e6d6611e --- /dev/null +++ b/libraries/RTC/examples/Example1_Get_Time/Example1_Get_Time.ino @@ -0,0 +1,46 @@ +/* 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. + 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 + section 12.1 for more information. + + 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 + +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(0, 51, 28, 7, 21, 10, 15); //Manually set RTC back to the future: Oct 21st, 2015 at 7:28.51 AM +} + +void loop() +{ + myRTC.getTime(); + + Serial.printf("It is now "); + Serial.printf("%d:", myRTC.hour); + Serial.printf("%02d:", myRTC.minute); + Serial.printf("%02d.", myRTC.seconds); + Serial.printf("%02d", myRTC.hundredths); + + Serial.printf(" %02d/", myRTC.month); + Serial.printf("%02d/", myRTC.dayOfMonth); + Serial.printf("%02d", myRTC.year); + + Serial.printf(" Day of week: %d =", myRTC.weekday); + Serial.printf(" %s", myRTC.textWeekday); + + Serial.println(); + + delay(1000); +} From fbcdc1d70add2c0178e6691935d92dbe1fb12fec Mon Sep 17 00:00:00 2001 From: Adam Date: Sat, 23 May 2020 15:12:08 -0400 Subject: [PATCH 21/51] Delete Example1_getTime.ino --- .../Example1_getTime/Example1_getTime.ino | 46 ------------------- 1 file changed, 46 deletions(-) delete mode 100644 libraries/RTC/examples/Example1_getTime/Example1_getTime.ino diff --git a/libraries/RTC/examples/Example1_getTime/Example1_getTime.ino b/libraries/RTC/examples/Example1_getTime/Example1_getTime.ino deleted file mode 100644 index e6d6611e..00000000 --- a/libraries/RTC/examples/Example1_getTime/Example1_getTime.ino +++ /dev/null @@ -1,46 +0,0 @@ -/* 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. - 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 - section 12.1 for more information. - - 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 - -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(0, 51, 28, 7, 21, 10, 15); //Manually set RTC back to the future: Oct 21st, 2015 at 7:28.51 AM -} - -void loop() -{ - myRTC.getTime(); - - Serial.printf("It is now "); - Serial.printf("%d:", myRTC.hour); - Serial.printf("%02d:", myRTC.minute); - Serial.printf("%02d.", myRTC.seconds); - Serial.printf("%02d", myRTC.hundredths); - - Serial.printf(" %02d/", myRTC.month); - Serial.printf("%02d/", myRTC.dayOfMonth); - Serial.printf("%02d", myRTC.year); - - Serial.printf(" Day of week: %d =", myRTC.weekday); - Serial.printf(" %s", myRTC.textWeekday); - - Serial.println(); - - delay(1000); -} From a53782ede9d2a35bf72308676ab28ca156ffca6b Mon Sep 17 00:00:00 2001 From: Adam Date: Sat, 23 May 2020 15:12:10 -0400 Subject: [PATCH 22/51] Create Example2_RTC_Sleep.ino --- .../Example2_RTC_Sleep/Example2_RTC_Sleep.ino | 81 +++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 libraries/RTC/examples/Example2_RTC_Sleep/Example2_RTC_Sleep.ino diff --git a/libraries/RTC/examples/Example2_RTC_Sleep/Example2_RTC_Sleep.ino b/libraries/RTC/examples/Example2_RTC_Sleep/Example2_RTC_Sleep.ino new file mode 100644 index 00000000..32c75dc7 --- /dev/null +++ b/libraries/RTC/examples/Example2_RTC_Sleep/Example2_RTC_Sleep.ino @@ -0,0 +1,81 @@ +/* Author: Nathan Seidle + Created: Septempter 27th, 2019 + License: MIT. See SparkFun Arduino Apollo3 Project for more information + + This example demonstrates how to put the core to sleep for a number of + milliseconds before waking and printing the current time/date. This + is helpful for checking power consumption of the core while RTC+CT6 are running. +*/ + +#include "RTC.h" //Include RTC library included with the Aruino_Apollo3 core +APM3_RTC myRTC; //Create instance of RTC class + +uint32_t msToSleep = 2000; //This is the user editable number of ms to sleep between RTC checks +#define TIMER_FREQ 3000000L //Counter/Timer 6 will use the HFRC oscillator of 3MHz +uint32_t sysTicksToSleep = msToSleep * (TIMER_FREQ / 1000); + +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(0, 51, 28, 7, 21, 10, 15); //Manually set RTC back to the future: Oct 21st, 2015 at 7:28.51 AM + + setupWakeTimer(); +} + +void loop() +{ + myRTC.getTime(); + + Serial.printf("It is now "); + Serial.printf("%d:", myRTC.hour); + Serial.printf("%02d:", myRTC.minute); + Serial.printf("%02d.", myRTC.seconds); + Serial.printf("%02d", myRTC.hundredths); + + Serial.printf(" %02d/", myRTC.month); + Serial.printf("%02d/", myRTC.dayOfMonth); + Serial.printf("%02d", myRTC.year); + + Serial.printf(" Day of week: %d =", myRTC.weekday); + Serial.printf(" %s", myRTC.textWeekday); + + Serial.println(); + + am_hal_sysctrl_sleep(AM_HAL_SYSCTRL_SLEEP_DEEP); //Sleepy time +} + +//We use counter/timer 6 for this example but 0 to 7 are available +//CT 7 is used for Software Serial. All CTs are used for Servo. +void setupWakeTimer() +{ + //Clear compare interrupt + am_hal_stimer_int_clear(AM_HAL_STIMER_INT_COMPAREG); //Use CT6 + + am_hal_stimer_int_enable(AM_HAL_STIMER_INT_COMPAREG); // Enable C/T G=6 + + //Don't change from 3MHz system timer, but enable G timer + am_hal_stimer_config(AM_HAL_STIMER_CFG_CLEAR | AM_HAL_STIMER_CFG_FREEZE); + am_hal_stimer_config(AM_HAL_STIMER_HFRC_3MHZ | AM_HAL_STIMER_CFG_COMPARE_G_ENABLE); + + //Setup ISR to trigger when the number of ms have elapsed + am_hal_stimer_compare_delta_set(6, sysTicksToSleep); + + //Enable the timer interrupt in the NVIC. + NVIC_EnableIRQ(STIMER_CMPR6_IRQn); +} + +//Called once number of milliseconds has passed +extern "C" void am_stimer_cmpr6_isr(void) +{ + uint32_t ui32Status = am_hal_stimer_int_status_get(false); + if (ui32Status & AM_HAL_STIMER_INT_COMPAREG) + { + am_hal_stimer_int_clear(AM_HAL_STIMER_INT_COMPAREG); + + //Reset compare value. ISR will trigger when the number of ms have elapsed + am_hal_stimer_compare_delta_set(6, sysTicksToSleep); + } +} From d16b64b1ad45dbe918f3566ab8112a8001921762 Mon Sep 17 00:00:00 2001 From: Adam Date: Sat, 23 May 2020 15:12:12 -0400 Subject: [PATCH 23/51] Delete Example2_RTCwithSleep.ino --- .../Example2_RTCwithSleep.ino | 81 ------------------- 1 file changed, 81 deletions(-) delete mode 100644 libraries/RTC/examples/Example2_RTCwithSleep/Example2_RTCwithSleep.ino diff --git a/libraries/RTC/examples/Example2_RTCwithSleep/Example2_RTCwithSleep.ino b/libraries/RTC/examples/Example2_RTCwithSleep/Example2_RTCwithSleep.ino deleted file mode 100644 index 32c75dc7..00000000 --- a/libraries/RTC/examples/Example2_RTCwithSleep/Example2_RTCwithSleep.ino +++ /dev/null @@ -1,81 +0,0 @@ -/* Author: Nathan Seidle - Created: Septempter 27th, 2019 - License: MIT. See SparkFun Arduino Apollo3 Project for more information - - This example demonstrates how to put the core to sleep for a number of - milliseconds before waking and printing the current time/date. This - is helpful for checking power consumption of the core while RTC+CT6 are running. -*/ - -#include "RTC.h" //Include RTC library included with the Aruino_Apollo3 core -APM3_RTC myRTC; //Create instance of RTC class - -uint32_t msToSleep = 2000; //This is the user editable number of ms to sleep between RTC checks -#define TIMER_FREQ 3000000L //Counter/Timer 6 will use the HFRC oscillator of 3MHz -uint32_t sysTicksToSleep = msToSleep * (TIMER_FREQ / 1000); - -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(0, 51, 28, 7, 21, 10, 15); //Manually set RTC back to the future: Oct 21st, 2015 at 7:28.51 AM - - setupWakeTimer(); -} - -void loop() -{ - myRTC.getTime(); - - Serial.printf("It is now "); - Serial.printf("%d:", myRTC.hour); - Serial.printf("%02d:", myRTC.minute); - Serial.printf("%02d.", myRTC.seconds); - Serial.printf("%02d", myRTC.hundredths); - - Serial.printf(" %02d/", myRTC.month); - Serial.printf("%02d/", myRTC.dayOfMonth); - Serial.printf("%02d", myRTC.year); - - Serial.printf(" Day of week: %d =", myRTC.weekday); - Serial.printf(" %s", myRTC.textWeekday); - - Serial.println(); - - am_hal_sysctrl_sleep(AM_HAL_SYSCTRL_SLEEP_DEEP); //Sleepy time -} - -//We use counter/timer 6 for this example but 0 to 7 are available -//CT 7 is used for Software Serial. All CTs are used for Servo. -void setupWakeTimer() -{ - //Clear compare interrupt - am_hal_stimer_int_clear(AM_HAL_STIMER_INT_COMPAREG); //Use CT6 - - am_hal_stimer_int_enable(AM_HAL_STIMER_INT_COMPAREG); // Enable C/T G=6 - - //Don't change from 3MHz system timer, but enable G timer - am_hal_stimer_config(AM_HAL_STIMER_CFG_CLEAR | AM_HAL_STIMER_CFG_FREEZE); - am_hal_stimer_config(AM_HAL_STIMER_HFRC_3MHZ | AM_HAL_STIMER_CFG_COMPARE_G_ENABLE); - - //Setup ISR to trigger when the number of ms have elapsed - am_hal_stimer_compare_delta_set(6, sysTicksToSleep); - - //Enable the timer interrupt in the NVIC. - NVIC_EnableIRQ(STIMER_CMPR6_IRQn); -} - -//Called once number of milliseconds has passed -extern "C" void am_stimer_cmpr6_isr(void) -{ - uint32_t ui32Status = am_hal_stimer_int_status_get(false); - if (ui32Status & AM_HAL_STIMER_INT_COMPAREG) - { - am_hal_stimer_int_clear(AM_HAL_STIMER_INT_COMPAREG); - - //Reset compare value. ISR will trigger when the number of ms have elapsed - am_hal_stimer_compare_delta_set(6, sysTicksToSleep); - } -} From 9b18daab0bb55ec039a3ff65a6884386016d1a96 Mon Sep 17 00:00:00 2001 From: Adam Date: Sat, 23 May 2020 15:12:14 -0400 Subject: [PATCH 24/51] Create Example3_Test_RTC.ino --- .../Example3_Test_RTC/Example3_Test_RTC.ino | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 libraries/RTC/examples/Example3_Test_RTC/Example3_Test_RTC.ino diff --git a/libraries/RTC/examples/Example3_Test_RTC/Example3_Test_RTC.ino b/libraries/RTC/examples/Example3_Test_RTC/Example3_Test_RTC.ino new file mode 100644 index 00000000..119895cb --- /dev/null +++ b/libraries/RTC/examples/Example3_Test_RTC/Example3_Test_RTC.ino @@ -0,0 +1,83 @@ +/* + 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 + +int previousDay = 1; + +void setup() +{ + Serial.begin(115200); + delay(10); + Serial.println("Artemis RTC testing"); + + //myRTC.setTime(hund, ss, mm, hh, dd, mm, yy); + myRTC.setTime(0, 59, 59, 23, 1, 1, 20); // Manually set RTC to 1s before midnight +} + +void loop() +{ + printArtemisTime(); + + myRTC.getTime(); + myRTC.setTime(99, 59, 59, 23, 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() +{ + char buf[50]; + char weekdayBuf[4]; + + myRTC.getTime(); + int i = myRTC.weekday + 1; + switch (i) + { + case (1): + strcpy(weekdayBuf, "Sun"); + break; + case (2): + strcpy(weekdayBuf, "Mon"); + break; + case (3): + strcpy(weekdayBuf, "Tue"); + break; + case (4): + strcpy(weekdayBuf, "Wed"); + break; + case (5): + strcpy(weekdayBuf, "Thu"); + break; + case (6): + strcpy(weekdayBuf, "Fri"); + break; + case (7): + strcpy(weekdayBuf, "Sat"); + break; + + default: + strcpy(weekdayBuf, "???"); + break; + } + + sprintf(buf, "%02d-%02d-%02d (%s) %02d:%02d:%02d.%02d", myRTC.year, myRTC.month, myRTC.dayOfMonth, weekdayBuf, myRTC.hour, myRTC.minute, myRTC.seconds, myRTC.hundredths); + Serial.print(buf); + + //Move the previous day forward one day and make sure it matches today + if ((previousDay + 1) % 7 != myRTC.weekday) + { + Serial.printf(" Error! previousDay: %d today: %d\n", previousDay, myRTC.weekday); + while (1) + ; + } + + previousDay = myRTC.weekday; + + Serial.println(); +} From d833ca129428172960441d8ada5f4ccba9c93d5b Mon Sep 17 00:00:00 2001 From: Adam Date: Sat, 23 May 2020 15:12:16 -0400 Subject: [PATCH 25/51] Delete Example3_TestRTC.ino --- .../Example3_TestRTC/Example3_TestRTC.ino | 82 ------------------- 1 file changed, 82 deletions(-) delete mode 100644 libraries/RTC/examples/Example3_TestRTC/Example3_TestRTC.ino diff --git a/libraries/RTC/examples/Example3_TestRTC/Example3_TestRTC.ino b/libraries/RTC/examples/Example3_TestRTC/Example3_TestRTC.ino deleted file mode 100644 index 6fb970b0..00000000 --- a/libraries/RTC/examples/Example3_TestRTC/Example3_TestRTC.ino +++ /dev/null @@ -1,82 +0,0 @@ -/* 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 - -int previousDay = 1; - -void setup() -{ - Serial.begin(115200); - delay(10); - Serial.println("Artemis RTC testing"); - - //myRTC.setTime(hund, ss, mm, hh, dd, mm, yy); - myRTC.setTime(0, 59, 59, 23, 1, 1, 20); // Manually set RTC to 1s before midnight -} - -void loop() -{ - printArtemisTime(); - - myRTC.getTime(); - myRTC.setTime(99, 59, 59, 23, 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() -{ - char buf[50]; - char weekdayBuf[4]; - - myRTC.getTime(); - int i = myRTC.weekday + 1; - switch (i) - { - case (1): - strcpy(weekdayBuf, "Sun"); - break; - case (2): - strcpy(weekdayBuf, "Mon"); - break; - case (3): - strcpy(weekdayBuf, "Tue"); - break; - case (4): - strcpy(weekdayBuf, "Wed"); - break; - case (5): - strcpy(weekdayBuf, "Thu"); - break; - case (6): - strcpy(weekdayBuf, "Fri"); - break; - case (7): - strcpy(weekdayBuf, "Sat"); - break; - - default: - strcpy(weekdayBuf, "???"); - break; - } - - sprintf(buf, "%02d-%02d-%02d (%s) %02d:%02d:%02d.%02d", myRTC.year, myRTC.month, myRTC.dayOfMonth, weekdayBuf, myRTC.hour, myRTC.minute, myRTC.seconds, myRTC.hundredths); - Serial.print(buf); - - //Move the previous day forward one day and make sure it matches today - if ((previousDay + 1) % 7 != myRTC.weekday) - { - Serial.printf(" Error! previousDay: %d today: %d\n", previousDay, myRTC.weekday); - while (1) - ; - } - - previousDay = myRTC.weekday; - - Serial.println(); -} From 2cf56bf0658edc954038b9c7918159f11a1898de Mon Sep 17 00:00:00 2001 From: Adam Date: Sat, 23 May 2020 15:12:19 -0400 Subject: [PATCH 26/51] Create Example4_Set_Epoch.ino --- .../Example4_Set_Epoch/Example4_Set_Epoch.ino | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 libraries/RTC/examples/Example4_Set_Epoch/Example4_Set_Epoch.ino diff --git a/libraries/RTC/examples/Example4_Set_Epoch/Example4_Set_Epoch.ino b/libraries/RTC/examples/Example4_Set_Epoch/Example4_Set_Epoch.ino new file mode 100644 index 00000000..b985c25a --- /dev/null +++ b/libraries/RTC/examples/Example4_Set_Epoch/Example4_Set_Epoch.ino @@ -0,0 +1,44 @@ +/* + Author: Adam Garbo + Created: May 23rd, 2020 + License: MIT. See SparkFun Arduino Apollo3 Project for more information + + This example demonstrates how to set the RTC using UNIX Epoch time. + + 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 + section 12.1 for more information. + +*/ + +#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(1590240780); // E.g. Saturday, May 23, 2020 1:33:00 PM +} + +void loop() +{ + Serial.print("Epoch time: "); Serial.println(myRTC.getEpoch()); + 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); +} From bad72344d7a039e2ee8601f2ed1190686145a41b Mon Sep 17 00:00:00 2001 From: Adam Date: Sat, 23 May 2020 15:12:21 -0400 Subject: [PATCH 27/51] Create Example5_Set_Alarms.ino --- .../Example5_Set_Alarms.ino | 94 +++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 libraries/RTC/examples/Example5_Set_Alarms/Example5_Set_Alarms.ino diff --git a/libraries/RTC/examples/Example5_Set_Alarms/Example5_Set_Alarms.ino b/libraries/RTC/examples/Example5_Set_Alarms/Example5_Set_Alarms.ino new file mode 100644 index 00000000..fb9aff31 --- /dev/null +++ b/libraries/RTC/examples/Example5_Set_Alarms/Example5_Set_Alarms.ino @@ -0,0 +1,94 @@ +/* + Author: Adam Garbo + Created: May 23rd, 2020 + License: MIT. See SparkFun Arduino Apollo3 Project for more information + + This example demonstrates how to read and set RTC alarms. + + 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 + section 12.1 for more information. +*/ + +#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"); + + //myRTC.setToCompilerTime(); // Easily set RTC using the system __DATE__ and __TIME__ macros from compiler + myRTC.setTime(0, 50, 59, 12, 23, 5, 20); // Manually set RTC date and time (hund, ss, mm, hh, dd, mm, yy) + + Serial.print("Initial alarm: "); printAlarm(); // Initial alarm should read all zeroes + + // Set the RTC's alarm + myRTC.setAlarm(0, 0, 0, 13, 23, 5); // Set alarm (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 + 2: Alarm match every month + 3: Alarm match every week + 4: Alarm match every day + 5: Alarm match every hour + 6: Alarm match every minute + 7: Alarm match every second + 8: Alarm match every 10th second + 9: Alarm match every 100th second + */ + myRTC.setAlarmMode(6); // Set the RTC alarm to match on minutes rollover + myRTC.attachInterrupt(); // Attach RTC alarm interrupt + + Serial.print("Next alarm: "); printAlarm(); // Print current alarm date and time +} + +void loop() +{ + if (alarmFlag == true) + { + Serial.print("Alarm triggered: "); printDateTime(); + alarmFlag = false; + } + + 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; +} From ea2e7eab1836afe80c60cf9dd6f87a66b01dba2e Mon Sep 17 00:00:00 2001 From: Adam Date: Sat, 23 May 2020 15:12:23 -0400 Subject: [PATCH 28/51] Create Example6_Rolling_Alarms.ino --- .../Example6_Rolling_Alarms.ino | 95 +++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 libraries/RTC/examples/Example6_Rolling_Alarms/Example6_Rolling_Alarms.ino diff --git a/libraries/RTC/examples/Example6_Rolling_Alarms/Example6_Rolling_Alarms.ino b/libraries/RTC/examples/Example6_Rolling_Alarms/Example6_Rolling_Alarms.ino new file mode 100644 index 00000000..bbfaf229 --- /dev/null +++ b/libraries/RTC/examples/Example6_Rolling_Alarms/Example6_Rolling_Alarms.ino @@ -0,0 +1,95 @@ +/* + Author: Adam Garbo + Created: May 23rd, 2020 + License: MIT. See SparkFun Arduino Apollo3 Project for more information + + This example demonstrates how to read and set rolling RTC alarms. +*/ + +#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 Rolling Alarms Example"); + + //myRTC.setToCompilerTime(); //Easily set RTC using the system __DATE__ and __TIME__ macros from compiler + myRTC.setTime(0, 50, 59, 12, 23, 5, 20); // Manually set RTC date and time (hund, ss, mm, hh, dd, mm, yy) + + Serial.print("Initial alarm: "); printAlarm(); // Initial alarm should read all zeroes + + // Set the RTC's alarm + myRTC.setAlarm(0, 0, 0, 13, 23, 5); // Set alarm (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 + 2: Alarm match every month + 3: Alarm match every week + 4: Alarm match every day + 5: Alarm match every hour + 6: Alarm match every minute + 7: Alarm match every second + 8: Alarm match every 10th second + 9: Alarm match every 100th second + */ + myRTC.setAlarmMode(6); // Set the RTC alarm to match on minutes rollover + myRTC.attachInterrupt(); // Attach RTC alarm interrupt + + Serial.print("Next alarm: "); printAlarm(); // Print current alarm date and time +} + +void loop() +{ + if (alarmFlag == true) + { + Serial.print("Alarm triggered: "); printDateTime(); + alarmFlag = false; + + // Set the RTC's rolling alarm + myRTC.setAlarm(0, (myRTC.seconds + 5) % 60, myRTC.minute, + myRTC.hour, myRTC.dayOfMonth, myRTC.month); + myRTC.setAlarmMode(2); + Serial.print("Rolling alarm: "); printAlarm(); + } + + 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; +} From 41e29143dab7b11bd1ddf3a9671e51d8056055b3 Mon Sep 17 00:00:00 2001 From: Adam Date: Sat, 23 May 2020 16:09:47 -0400 Subject: [PATCH 29/51] Update Example6_Rolling_Alarms.ino --- .../Example6_Rolling_Alarms/Example6_Rolling_Alarms.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/RTC/examples/Example6_Rolling_Alarms/Example6_Rolling_Alarms.ino b/libraries/RTC/examples/Example6_Rolling_Alarms/Example6_Rolling_Alarms.ino index bbfaf229..4d7fa4d6 100644 --- a/libraries/RTC/examples/Example6_Rolling_Alarms/Example6_Rolling_Alarms.ino +++ b/libraries/RTC/examples/Example6_Rolling_Alarms/Example6_Rolling_Alarms.ino @@ -53,7 +53,7 @@ void loop() // Set the RTC's rolling alarm myRTC.setAlarm(0, (myRTC.seconds + 5) % 60, myRTC.minute, myRTC.hour, myRTC.dayOfMonth, myRTC.month); - myRTC.setAlarmMode(2); + myRTC.setAlarmMode(6); Serial.print("Rolling alarm: "); printAlarm(); } From 55571c5062341c992fb34beca88386a9be89a5ad Mon Sep 17 00:00:00 2001 From: Adam Date: Tue, 26 May 2020 15:03:00 -0400 Subject: [PATCH 30/51] Update Example6_Rolling_Alarms.ino --- .../Example6_Rolling_Alarms.ino | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/libraries/RTC/examples/Example6_Rolling_Alarms/Example6_Rolling_Alarms.ino b/libraries/RTC/examples/Example6_Rolling_Alarms/Example6_Rolling_Alarms.ino index 4d7fa4d6..9ba56fa2 100644 --- a/libraries/RTC/examples/Example6_Rolling_Alarms/Example6_Rolling_Alarms.ino +++ b/libraries/RTC/examples/Example6_Rolling_Alarms/Example6_Rolling_Alarms.ino @@ -10,6 +10,12 @@ APM3_RTC myRTC; //Create instance of RTC class volatile bool alarmFlag = false; +int alarmSeconds = 5; +int alarmMinutes = 0; +int alarmHours = 0; +int alarmDays = 0; +int alarmMonths = 0; + void setup() { @@ -51,8 +57,11 @@ void loop() alarmFlag = false; // Set the RTC's rolling alarm - myRTC.setAlarm(0, (myRTC.seconds + 5) % 60, myRTC.minute, - myRTC.hour, myRTC.dayOfMonth, myRTC.month); + myRTC.setAlarm(0, (myRTC.seconds + alarmSeconds) % 60, + (myRTC.minute + alarmMinutes) % 60, + (myRTC.hour + alarmHours) % 24, + (myRTC.dayOfMonth + alarmDay) % 31, // To do: How to # days in a month rollovers + (myRTC.month + alarmMonth) % 12); myRTC.setAlarmMode(6); Serial.print("Rolling alarm: "); printAlarm(); } From 7dafea2b01d2285637224fdf43f886fe0f9e11eb Mon Sep 17 00:00:00 2001 From: Adam Date: Tue, 26 May 2020 15:07:19 -0400 Subject: [PATCH 31/51] Update Example6_Rolling_Alarms.ino --- .../Example6_Rolling_Alarms/Example6_Rolling_Alarms.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/RTC/examples/Example6_Rolling_Alarms/Example6_Rolling_Alarms.ino b/libraries/RTC/examples/Example6_Rolling_Alarms/Example6_Rolling_Alarms.ino index 9ba56fa2..657b7276 100644 --- a/libraries/RTC/examples/Example6_Rolling_Alarms/Example6_Rolling_Alarms.ino +++ b/libraries/RTC/examples/Example6_Rolling_Alarms/Example6_Rolling_Alarms.ino @@ -13,8 +13,8 @@ volatile bool alarmFlag = false; int alarmSeconds = 5; int alarmMinutes = 0; int alarmHours = 0; -int alarmDays = 0; -int alarmMonths = 0; +int alarmDay = 0; +int alarmMonth = 0; void setup() From 9d2390b642b9280d3c7df4de4c714f5a1994854d Mon Sep 17 00:00:00 2001 From: Adam Date: Wed, 3 Jun 2020 11:03:13 -0400 Subject: [PATCH 32/51] Delete Example2_RTC_Sleep.ino --- .../Example2_RTC_Sleep/Example2_RTC_Sleep.ino | 81 ------------------- 1 file changed, 81 deletions(-) delete mode 100644 libraries/RTC/examples/Example2_RTC_Sleep/Example2_RTC_Sleep.ino diff --git a/libraries/RTC/examples/Example2_RTC_Sleep/Example2_RTC_Sleep.ino b/libraries/RTC/examples/Example2_RTC_Sleep/Example2_RTC_Sleep.ino deleted file mode 100644 index 32c75dc7..00000000 --- a/libraries/RTC/examples/Example2_RTC_Sleep/Example2_RTC_Sleep.ino +++ /dev/null @@ -1,81 +0,0 @@ -/* Author: Nathan Seidle - Created: Septempter 27th, 2019 - License: MIT. See SparkFun Arduino Apollo3 Project for more information - - This example demonstrates how to put the core to sleep for a number of - milliseconds before waking and printing the current time/date. This - is helpful for checking power consumption of the core while RTC+CT6 are running. -*/ - -#include "RTC.h" //Include RTC library included with the Aruino_Apollo3 core -APM3_RTC myRTC; //Create instance of RTC class - -uint32_t msToSleep = 2000; //This is the user editable number of ms to sleep between RTC checks -#define TIMER_FREQ 3000000L //Counter/Timer 6 will use the HFRC oscillator of 3MHz -uint32_t sysTicksToSleep = msToSleep * (TIMER_FREQ / 1000); - -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(0, 51, 28, 7, 21, 10, 15); //Manually set RTC back to the future: Oct 21st, 2015 at 7:28.51 AM - - setupWakeTimer(); -} - -void loop() -{ - myRTC.getTime(); - - Serial.printf("It is now "); - Serial.printf("%d:", myRTC.hour); - Serial.printf("%02d:", myRTC.minute); - Serial.printf("%02d.", myRTC.seconds); - Serial.printf("%02d", myRTC.hundredths); - - Serial.printf(" %02d/", myRTC.month); - Serial.printf("%02d/", myRTC.dayOfMonth); - Serial.printf("%02d", myRTC.year); - - Serial.printf(" Day of week: %d =", myRTC.weekday); - Serial.printf(" %s", myRTC.textWeekday); - - Serial.println(); - - am_hal_sysctrl_sleep(AM_HAL_SYSCTRL_SLEEP_DEEP); //Sleepy time -} - -//We use counter/timer 6 for this example but 0 to 7 are available -//CT 7 is used for Software Serial. All CTs are used for Servo. -void setupWakeTimer() -{ - //Clear compare interrupt - am_hal_stimer_int_clear(AM_HAL_STIMER_INT_COMPAREG); //Use CT6 - - am_hal_stimer_int_enable(AM_HAL_STIMER_INT_COMPAREG); // Enable C/T G=6 - - //Don't change from 3MHz system timer, but enable G timer - am_hal_stimer_config(AM_HAL_STIMER_CFG_CLEAR | AM_HAL_STIMER_CFG_FREEZE); - am_hal_stimer_config(AM_HAL_STIMER_HFRC_3MHZ | AM_HAL_STIMER_CFG_COMPARE_G_ENABLE); - - //Setup ISR to trigger when the number of ms have elapsed - am_hal_stimer_compare_delta_set(6, sysTicksToSleep); - - //Enable the timer interrupt in the NVIC. - NVIC_EnableIRQ(STIMER_CMPR6_IRQn); -} - -//Called once number of milliseconds has passed -extern "C" void am_stimer_cmpr6_isr(void) -{ - uint32_t ui32Status = am_hal_stimer_int_status_get(false); - if (ui32Status & AM_HAL_STIMER_INT_COMPAREG) - { - am_hal_stimer_int_clear(AM_HAL_STIMER_INT_COMPAREG); - - //Reset compare value. ISR will trigger when the number of ms have elapsed - am_hal_stimer_compare_delta_set(6, sysTicksToSleep); - } -} From 0a7c95600eb4eb76222dd821232f2a95988f2473 Mon Sep 17 00:00:00 2001 From: Adam Date: Wed, 3 Jun 2020 11:03:17 -0400 Subject: [PATCH 33/51] Delete Example5_Set_Alarms.ino --- .../Example5_Set_Alarms.ino | 94 ------------------- 1 file changed, 94 deletions(-) delete mode 100644 libraries/RTC/examples/Example5_Set_Alarms/Example5_Set_Alarms.ino diff --git a/libraries/RTC/examples/Example5_Set_Alarms/Example5_Set_Alarms.ino b/libraries/RTC/examples/Example5_Set_Alarms/Example5_Set_Alarms.ino deleted file mode 100644 index fb9aff31..00000000 --- a/libraries/RTC/examples/Example5_Set_Alarms/Example5_Set_Alarms.ino +++ /dev/null @@ -1,94 +0,0 @@ -/* - Author: Adam Garbo - Created: May 23rd, 2020 - License: MIT. See SparkFun Arduino Apollo3 Project for more information - - This example demonstrates how to read and set RTC alarms. - - 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 - section 12.1 for more information. -*/ - -#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"); - - //myRTC.setToCompilerTime(); // Easily set RTC using the system __DATE__ and __TIME__ macros from compiler - myRTC.setTime(0, 50, 59, 12, 23, 5, 20); // Manually set RTC date and time (hund, ss, mm, hh, dd, mm, yy) - - Serial.print("Initial alarm: "); printAlarm(); // Initial alarm should read all zeroes - - // Set the RTC's alarm - myRTC.setAlarm(0, 0, 0, 13, 23, 5); // Set alarm (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 - 2: Alarm match every month - 3: Alarm match every week - 4: Alarm match every day - 5: Alarm match every hour - 6: Alarm match every minute - 7: Alarm match every second - 8: Alarm match every 10th second - 9: Alarm match every 100th second - */ - myRTC.setAlarmMode(6); // Set the RTC alarm to match on minutes rollover - myRTC.attachInterrupt(); // Attach RTC alarm interrupt - - Serial.print("Next alarm: "); printAlarm(); // Print current alarm date and time -} - -void loop() -{ - if (alarmFlag == true) - { - Serial.print("Alarm triggered: "); printDateTime(); - alarmFlag = false; - } - - 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; -} From ac0bcd00c93167c8fdfbfe57712311dca8039204 Mon Sep 17 00:00:00 2001 From: Adam Date: Wed, 3 Jun 2020 11:03:20 -0400 Subject: [PATCH 34/51] Delete Example6_Rolling_Alarms.ino --- .../Example6_Rolling_Alarms.ino | 104 ------------------ 1 file changed, 104 deletions(-) delete mode 100644 libraries/RTC/examples/Example6_Rolling_Alarms/Example6_Rolling_Alarms.ino diff --git a/libraries/RTC/examples/Example6_Rolling_Alarms/Example6_Rolling_Alarms.ino b/libraries/RTC/examples/Example6_Rolling_Alarms/Example6_Rolling_Alarms.ino deleted file mode 100644 index 657b7276..00000000 --- a/libraries/RTC/examples/Example6_Rolling_Alarms/Example6_Rolling_Alarms.ino +++ /dev/null @@ -1,104 +0,0 @@ -/* - Author: Adam Garbo - Created: May 23rd, 2020 - License: MIT. See SparkFun Arduino Apollo3 Project for more information - - This example demonstrates how to read and set rolling RTC alarms. -*/ - -#include "RTC.h" //Include RTC library included with the Aruino_Apollo3 core -APM3_RTC myRTC; //Create instance of RTC class - -volatile bool alarmFlag = false; -int alarmSeconds = 5; -int alarmMinutes = 0; -int alarmHours = 0; -int alarmDay = 0; -int alarmMonth = 0; - - -void setup() -{ - Serial.begin(115200); - Serial.println("SparkFun RTC Set Rolling Alarms Example"); - - //myRTC.setToCompilerTime(); //Easily set RTC using the system __DATE__ and __TIME__ macros from compiler - myRTC.setTime(0, 50, 59, 12, 23, 5, 20); // Manually set RTC date and time (hund, ss, mm, hh, dd, mm, yy) - - Serial.print("Initial alarm: "); printAlarm(); // Initial alarm should read all zeroes - - // Set the RTC's alarm - myRTC.setAlarm(0, 0, 0, 13, 23, 5); // Set alarm (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 - 2: Alarm match every month - 3: Alarm match every week - 4: Alarm match every day - 5: Alarm match every hour - 6: Alarm match every minute - 7: Alarm match every second - 8: Alarm match every 10th second - 9: Alarm match every 100th second - */ - myRTC.setAlarmMode(6); // Set the RTC alarm to match on minutes rollover - myRTC.attachInterrupt(); // Attach RTC alarm interrupt - - Serial.print("Next alarm: "); printAlarm(); // Print current alarm date and time -} - -void loop() -{ - if (alarmFlag == true) - { - Serial.print("Alarm triggered: "); printDateTime(); - alarmFlag = false; - - // Set the RTC's rolling alarm - myRTC.setAlarm(0, (myRTC.seconds + alarmSeconds) % 60, - (myRTC.minute + alarmMinutes) % 60, - (myRTC.hour + alarmHours) % 24, - (myRTC.dayOfMonth + alarmDay) % 31, // To do: How to # days in a month rollovers - (myRTC.month + alarmMonth) % 12); - myRTC.setAlarmMode(6); - Serial.print("Rolling alarm: "); printAlarm(); - } - - 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; -} From ca602fe0d9abcb0ae16974bb6174d7af83eacfdf Mon Sep 17 00:00:00 2001 From: Adam Date: Wed, 3 Jun 2020 11:03:23 -0400 Subject: [PATCH 35/51] Update Example1_Get_Time.ino --- .../Example1_Get_Time/Example1_Get_Time.ino | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/libraries/RTC/examples/Example1_Get_Time/Example1_Get_Time.ino b/libraries/RTC/examples/Example1_Get_Time/Example1_Get_Time.ino index e6d6611e..e29ed841 100644 --- a/libraries/RTC/examples/Example1_Get_Time/Example1_Get_Time.ino +++ b/libraries/RTC/examples/Example1_Get_Time/Example1_Get_Time.ino @@ -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 @@ -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(0, 51, 28, 7, 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(0, 50, 59, 12, 3, 6, 20); // 12:59:50.000, June 3rd, 2020 (hund, ss, mm, hh, dd, mm, yy) } void loop() @@ -33,9 +38,9 @@ void loop() Serial.printf("%02d.", myRTC.seconds); Serial.printf("%02d", myRTC.hundredths); - Serial.printf(" %02d/", myRTC.month); - Serial.printf("%02d/", myRTC.dayOfMonth); - Serial.printf("%02d", myRTC.year); + Serial.printf(" 20%d/", myRTC.year); + Serial.printf("%02d/", myRTC.month); + Serial.printf("%02d", myRTC.dayOfMonth); Serial.printf(" Day of week: %d =", myRTC.weekday); Serial.printf(" %s", myRTC.textWeekday); From 877ac2d2ccc5ff85ae121d17eb28587ef442dcfa Mon Sep 17 00:00:00 2001 From: Adam Date: Wed, 3 Jun 2020 11:03:25 -0400 Subject: [PATCH 36/51] Create Example2_Set_Alarms.ino --- .../Example2_Set_Alarms.ino | 97 +++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 libraries/RTC/examples/Example2_Set_Alarms/Example2_Set_Alarms.ino diff --git a/libraries/RTC/examples/Example2_Set_Alarms/Example2_Set_Alarms.ino b/libraries/RTC/examples/Example2_Set_Alarms/Example2_Set_Alarms.ino new file mode 100644 index 00000000..a0076302 --- /dev/null +++ b/libraries/RTC/examples/Example2_Set_Alarms/Example2_Set_Alarms.ino @@ -0,0 +1,97 @@ +/* + 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. 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(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 + myRTC.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 + /* + 0: Alarm interrupt disabled + 1: Alarm match every year + 2: Alarm match every month + 3: Alarm match every week + 4: Alarm match every day + 5: Alarm match every hour + 6: Alarm match every minute + 7: Alarm match every second + */ + 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; +} From 6847614431750ddcc05e6fcd4511632211ae9665 Mon Sep 17 00:00:00 2001 From: Adam Date: Wed, 3 Jun 2020 11:03:27 -0400 Subject: [PATCH 37/51] Update Example3_Test_RTC.ino --- .../RTC/examples/Example3_Test_RTC/Example3_Test_RTC.ino | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libraries/RTC/examples/Example3_Test_RTC/Example3_Test_RTC.ino b/libraries/RTC/examples/Example3_Test_RTC/Example3_Test_RTC.ino index 119895cb..e8e69a24 100644 --- a/libraries/RTC/examples/Example3_Test_RTC/Example3_Test_RTC.ino +++ b/libraries/RTC/examples/Example3_Test_RTC/Example3_Test_RTC.ino @@ -15,10 +15,10 @@ void setup() { Serial.begin(115200); delay(10); - Serial.println("Artemis RTC testing"); + Serial.println("Artemis RTC Testing"); - //myRTC.setTime(hund, ss, mm, hh, dd, mm, yy); - myRTC.setTime(0, 59, 59, 23, 1, 1, 20); // Manually set RTC to 1s before midnight + // Manually set RTC date and time + myRTC.setTime(0, 59, 59, 23, 1, 1, 20); // Set to 1 second before midnight } void loop() @@ -26,7 +26,7 @@ void loop() printArtemisTime(); myRTC.getTime(); - myRTC.setTime(99, 59, 59, 23, myRTC.dayOfMonth, myRTC.month, myRTC.year); //Manually set RTC + myRTC.setTime(99, 59, 59, 23, myRTC.dayOfMonth, myRTC.month, myRTC.year); // Manually set RTC delay(11); //Allow us to roll from midnight the night before to the new day } From c23d225552b8455ea3c0f4db51d66f82cffb050f Mon Sep 17 00:00:00 2001 From: Adam Date: Wed, 3 Jun 2020 11:03:30 -0400 Subject: [PATCH 38/51] Update Example4_Set_Epoch.ino --- .../Example4_Set_Epoch/Example4_Set_Epoch.ino | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/libraries/RTC/examples/Example4_Set_Epoch/Example4_Set_Epoch.ino b/libraries/RTC/examples/Example4_Set_Epoch/Example4_Set_Epoch.ino index b985c25a..04dd33d5 100644 --- a/libraries/RTC/examples/Example4_Set_Epoch/Example4_Set_Epoch.ino +++ b/libraries/RTC/examples/Example4_Set_Epoch/Example4_Set_Epoch.ino @@ -1,19 +1,13 @@ /* - Author: Adam Garbo - Created: May 23rd, 2020 + 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. - - 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 - section 12.1 for more information. - */ -#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() { @@ -21,12 +15,15 @@ void setup() Serial.println("SparkFun RTC Set UNIX Epoch Time Example"); // Set the RTC time using UNIX Epoch time - myRTC.setEpoch(1590240780); // E.g. Saturday, May 23, 2020 1:33:00 PM + 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); From 33839507a2d3af2a906750f3353d3b2ccf73dc19 Mon Sep 17 00:00:00 2001 From: Adam Date: Wed, 3 Jun 2020 11:03:32 -0400 Subject: [PATCH 39/51] Create Example5_Rolling_Alarms.ino --- .../Example5_Rolling_Alarms.ino | 109 ++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 libraries/RTC/examples/Example5_Rolling_Alarms/Example5_Rolling_Alarms.ino diff --git a/libraries/RTC/examples/Example5_Rolling_Alarms/Example5_Rolling_Alarms.ino b/libraries/RTC/examples/Example5_Rolling_Alarms/Example5_Rolling_Alarms.ino new file mode 100644 index 00000000..037c403b --- /dev/null +++ b/libraries/RTC/examples/Example5_Rolling_Alarms/Example5_Rolling_Alarms.ino @@ -0,0 +1,109 @@ +/* + Author: Adam Garbo and Nathan Seidle + Created: June 3rdrd, 2020 + License: MIT. See SparkFun Arduino Apollo3 Project for more information + + 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. +*/ + +#include "RTC.h" // Include RTC library included with the Aruino_Apollo3 core +APM3_RTC myRTC; // Create instance of RTC class + +volatile bool alarmFlag = false; +int alarmSeconds = 5; +int alarmMinutes = 0; +int alarmHours = 0; + +void setup() +{ + Serial.begin(115200); + Serial.println("SparkFun RTC Set Rolling Alarms Example"); + + // Easily set RTC using the system __DATE__ and __TIME__ macros from compiler + //myRTC.setToCompilerTime(); + + // Manually set RTC date and time + myRTC.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 + myRTC.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 + /* + 0: Alarm interrupt disabled + 1: Alarm match every year + 2: Alarm match every month + 3: Alarm match every week + 4: Alarm match every day + 5: Alarm match every hour + 6: Alarm match every minute + 7: Alarm match every second + */ + 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; + + // Set the RTC's rolling alarm + myRTC.setAlarm(0, (myRTC.seconds + alarmSeconds) % 60, + (myRTC.minute + alarmMinutes) % 60, + (myRTC.hour + alarmHours) % 24, + myRTC.dayOfMonth, + myRTC.month); + myRTC.setAlarmMode(6); + + // Print next RTC alarm date and time + Serial.print("Next rolling alarm: "); printAlarm(); + } +} + +// 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; +} From f3f7ac72ab3cafc6037250b73eacc0d6b5e49d25 Mon Sep 17 00:00:00 2001 From: Adam Date: Wed, 3 Jun 2020 11:03:34 -0400 Subject: [PATCH 40/51] Create Example6_LowPower_Alarm.ino --- .../Example6_LowPower_Alarm.ino | 129 ++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 libraries/RTC/examples/Example6_LowPower_Alarm/Example6_LowPower_Alarm.ino diff --git a/libraries/RTC/examples/Example6_LowPower_Alarm/Example6_LowPower_Alarm.ino b/libraries/RTC/examples/Example6_LowPower_Alarm/Example6_LowPower_Alarm.ino new file mode 100644 index 00000000..a3356c4e --- /dev/null +++ b/libraries/RTC/examples/Example6_LowPower_Alarm/Example6_LowPower_Alarm.ino @@ -0,0 +1,129 @@ +/* + 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 an RTC alarm and enter deep sleep. + + The code is configured to set an RTC alarm every minute and enter + deep sleep between interrupts. The RTC interrupt service routine will + wake the board and print the date and time upon each alarm interrupt. + + Tested with a SparkFun Edge 2. Confirmed sleep current of 2.5 uA. +*/ + +#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 Low-power Alarm Example"); + + // Easily set RTC using the system __DATE__ and __TIME__ macros from compiler + //myRTC.setToCompilerTime(); + + // Manually set RTC date and time + myRTC.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 + myRTC.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 + /* + 0: Alarm interrupt disabled + 1: Alarm match every year + 2: Alarm match every month + 3: Alarm match every week + 4: Alarm match every day + 5: Alarm match every hour + 6: Alarm match every minute + 7: Alarm match every second + */ + myRTC.setAlarmMode(6); // Set the RTC alarm to match on minutes rollover + myRTC.attachInterrupt(); // Attach RTC alarm interrupt +} + +void loop() +{ + // Print date and time of RTC alarm trigger + Serial.print("Alarm interrupt: "); printDateTime(); + + // Enter deep sleep and await RTC alarm interrupt + goToSleep(); +} + +// 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); +} + +// Power down gracefully +void goToSleep() +{ + // Disable UART + Serial.end(); + + // Disable ADC + power_adc_disable(); + + // Force the peripherals off + am_hal_pwrctrl_periph_disable(AM_HAL_PWRCTRL_PERIPH_IOM0); + am_hal_pwrctrl_periph_disable(AM_HAL_PWRCTRL_PERIPH_IOM1); + am_hal_pwrctrl_periph_disable(AM_HAL_PWRCTRL_PERIPH_IOM2); + am_hal_pwrctrl_periph_disable(AM_HAL_PWRCTRL_PERIPH_IOM3); + am_hal_pwrctrl_periph_disable(AM_HAL_PWRCTRL_PERIPH_IOM4); + am_hal_pwrctrl_periph_disable(AM_HAL_PWRCTRL_PERIPH_IOM5); + am_hal_pwrctrl_periph_disable(AM_HAL_PWRCTRL_PERIPH_ADC); + am_hal_pwrctrl_periph_disable(AM_HAL_PWRCTRL_PERIPH_UART0); + am_hal_pwrctrl_periph_disable(AM_HAL_PWRCTRL_PERIPH_UART1); + + // Disable all pads + for (int x = 0 ; x < 50 ; x++) + am_hal_gpio_pinconfig(x, g_AM_HAL_GPIO_DISABLE); + + //Power down Flash, SRAM, cache + am_hal_pwrctrl_memory_deepsleep_powerdown(AM_HAL_PWRCTRL_MEM_CACHE); // Turn off CACHE + am_hal_pwrctrl_memory_deepsleep_powerdown(AM_HAL_PWRCTRL_MEM_FLASH_512K); // Turn off everything but lower 512k + am_hal_pwrctrl_memory_deepsleep_powerdown(AM_HAL_PWRCTRL_MEM_SRAM_64K_DTCM); // Turn off everything but lower 64k + //am_hal_pwrctrl_memory_deepsleep_powerdown(AM_HAL_PWRCTRL_MEM_ALL); //Turn off all memory (doesn't recover) + + // Keep the 32kHz clock running for RTC + am_hal_stimer_config(AM_HAL_STIMER_CFG_CLEAR | AM_HAL_STIMER_CFG_FREEZE); + am_hal_stimer_config(AM_HAL_STIMER_XTAL_32KHZ); + + am_hal_sysctrl_sleep(AM_HAL_SYSCTRL_SLEEP_DEEP); // Sleep forever + + // And we're back! + wakeUp(); +} + +// Power up gracefully +void wakeUp() +{ + // Power up SRAM, turn on entire Flash + am_hal_pwrctrl_memory_deepsleep_powerdown(AM_HAL_PWRCTRL_MEM_MAX); + + // Go back to using the main clock + am_hal_stimer_config(AM_HAL_STIMER_CFG_CLEAR | AM_HAL_STIMER_CFG_FREEZE); + am_hal_stimer_config(AM_HAL_STIMER_HFRC_3MHZ); + + // Enable ADC + ap3_adc_setup(); + + // Enable Serial + Serial.begin(115200); +} + +// 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); +} From 2432faac6652191f1330dee917b33bcc9de1e26e Mon Sep 17 00:00:00 2001 From: Adam Date: Wed, 3 Jun 2020 11:04:33 -0400 Subject: [PATCH 41/51] Update RTC.cpp --- libraries/RTC/src/RTC.cpp | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/libraries/RTC/src/RTC.cpp b/libraries/RTC/src/RTC.cpp index 105f688c..4a562f94 100644 --- a/libraries/RTC/src/RTC.cpp +++ b/libraries/RTC/src/RTC.cpp @@ -179,8 +179,8 @@ void APM3_RTC::setAlarm(uint8_t hund, uint8_t sec, uint8_t min, uint8_t hour, ui 5: AM_HAL_RTC_ALM_RPT_HR Interrupt every hour 6: AM_HAL_RTC_ALM_RPT_MIN Interrupt every minute 7: AM_HAL_RTC_ALM_RPT_SEC Interrupt every second - 8: AM_HAL_RTC_ALM_RPT_10TH Interrupt every 10th second - 9: AM_HAL_RTC_ALM_RPT_100TH Interrupt every 100th second + 8: AM_HAL_RTC_ALM_RPT_10TH Interrupt every 10th second (unused) + 9: AM_HAL_RTC_ALM_RPT_100TH Interrupt every 100th second (unused) */ void APM3_RTC::setAlarmMode(uint8_t mode) { @@ -197,17 +197,10 @@ void APM3_RTC::attachInterrupt() // Enable RTC interrupts to the NVIC. NVIC_EnableIRQ(RTC_IRQn); - - // Enable interrupt signals from the NVIC to trigger ISR entry in the CPU. (Redundant?) - //am_hal_interrupt_master_enable(); - } void APM3_RTC::detachInterrupt() { - // Disable interrupt signals from the NVIC to trigger ISR entry in the CPU. (Redundant?) - // am_hal_interrupt_master_disable(); - // Disable RTC interrupts to the NVIC. NVIC_DisableIRQ(RTC_IRQn); From ebb80e55cdad7725e57bae85cc063e6fae9da1e8 Mon Sep 17 00:00:00 2001 From: Adam Date: Wed, 3 Jun 2020 11:06:08 -0400 Subject: [PATCH 42/51] Update library.properties --- libraries/RTC/library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/RTC/library.properties b/libraries/RTC/library.properties index 204d0812..659e1890 100644 --- a/libraries/RTC/library.properties +++ b/libraries/RTC/library.properties @@ -1,5 +1,5 @@ name=RTC -version=1.1 +version=1.2 author=SparkFun Electronics maintainer=SparkFun Electronics sentence=Real Time Clock (RTC)) library for the SparkFun Artemis From e691f2f88b949cd415155f000cd7f8f0f13a26a2 Mon Sep 17 00:00:00 2001 From: Adam Date: Wed, 3 Jun 2020 11:19:22 -0400 Subject: [PATCH 43/51] Update RTC alarm comparisons --- .../Example2_Set_Alarms.ino | 27 +++++++++++-------- .../Example5_Rolling_Alarms.ino | 14 +++++----- .../Example6_LowPower_Alarm.ino | 14 +++++----- 3 files changed, 30 insertions(+), 25 deletions(-) diff --git a/libraries/RTC/examples/Example2_Set_Alarms/Example2_Set_Alarms.ino b/libraries/RTC/examples/Example2_Set_Alarms/Example2_Set_Alarms.ino index a0076302..f8ee8308 100644 --- a/libraries/RTC/examples/Example2_Set_Alarms/Example2_Set_Alarms.ino +++ b/libraries/RTC/examples/Example2_Set_Alarms/Example2_Set_Alarms.ino @@ -3,10 +3,15 @@ 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. 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. + 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 @@ -31,13 +36,13 @@ void setup() // Set the RTC alarm mode /* 0: Alarm interrupt disabled - 1: Alarm match every year - 2: Alarm match every month - 3: Alarm match every week - 4: Alarm match every day - 5: Alarm match every hour - 6: Alarm match every minute - 7: Alarm match every second + 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 diff --git a/libraries/RTC/examples/Example5_Rolling_Alarms/Example5_Rolling_Alarms.ino b/libraries/RTC/examples/Example5_Rolling_Alarms/Example5_Rolling_Alarms.ino index 037c403b..5501e9e6 100644 --- a/libraries/RTC/examples/Example5_Rolling_Alarms/Example5_Rolling_Alarms.ino +++ b/libraries/RTC/examples/Example5_Rolling_Alarms/Example5_Rolling_Alarms.ino @@ -36,13 +36,13 @@ void setup() // Set the RTC alarm mode /* 0: Alarm interrupt disabled - 1: Alarm match every year - 2: Alarm match every month - 3: Alarm match every week - 4: Alarm match every day - 5: Alarm match every hour - 6: Alarm match every minute - 7: Alarm match every second + 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 diff --git a/libraries/RTC/examples/Example6_LowPower_Alarm/Example6_LowPower_Alarm.ino b/libraries/RTC/examples/Example6_LowPower_Alarm/Example6_LowPower_Alarm.ino index a3356c4e..36433967 100644 --- a/libraries/RTC/examples/Example6_LowPower_Alarm/Example6_LowPower_Alarm.ino +++ b/libraries/RTC/examples/Example6_LowPower_Alarm/Example6_LowPower_Alarm.ino @@ -32,13 +32,13 @@ void setup() // Set the RTC alarm mode /* 0: Alarm interrupt disabled - 1: Alarm match every year - 2: Alarm match every month - 3: Alarm match every week - 4: Alarm match every day - 5: Alarm match every hour - 6: Alarm match every minute - 7: Alarm match every second + 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 From f27f5a7ff16f34d57407643c6e0f657a0f97cf09 Mon Sep 17 00:00:00 2001 From: oclyke Date: Tue, 14 Jul 2020 14:22:22 -0600 Subject: [PATCH 44/51] restore Example1 date format --- .../RTC/examples/Example1_Get_Time/Example1_Get_Time.ino | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libraries/RTC/examples/Example1_Get_Time/Example1_Get_Time.ino b/libraries/RTC/examples/Example1_Get_Time/Example1_Get_Time.ino index e29ed841..c8fb3d6d 100644 --- a/libraries/RTC/examples/Example1_Get_Time/Example1_Get_Time.ino +++ b/libraries/RTC/examples/Example1_Get_Time/Example1_Get_Time.ino @@ -38,9 +38,9 @@ void loop() Serial.printf("%02d.", myRTC.seconds); Serial.printf("%02d", myRTC.hundredths); - Serial.printf(" 20%d/", myRTC.year); - Serial.printf("%02d/", myRTC.month); - Serial.printf("%02d", myRTC.dayOfMonth); + Serial.printf(" 20%d/", myRTC.month); + Serial.printf("%02d/", myRTC.dayOfMonth); + Serial.printf("%02d", myRTC.year); Serial.printf(" Day of week: %d =", myRTC.weekday); Serial.printf(" %s", myRTC.textWeekday); From 670d7fb2fc3f6d5a8c5560140ff31c7e46344081 Mon Sep 17 00:00:00 2001 From: oclyke Date: Tue, 14 Jul 2020 14:24:04 -0600 Subject: [PATCH 45/51] fix typo in Example1 restore --- libraries/RTC/examples/Example1_Get_Time/Example1_Get_Time.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/RTC/examples/Example1_Get_Time/Example1_Get_Time.ino b/libraries/RTC/examples/Example1_Get_Time/Example1_Get_Time.ino index c8fb3d6d..2b489b90 100644 --- a/libraries/RTC/examples/Example1_Get_Time/Example1_Get_Time.ino +++ b/libraries/RTC/examples/Example1_Get_Time/Example1_Get_Time.ino @@ -38,7 +38,7 @@ void loop() Serial.printf("%02d.", myRTC.seconds); Serial.printf("%02d", myRTC.hundredths); - Serial.printf(" 20%d/", myRTC.month); + Serial.printf(" %02d/", myRTC.month); Serial.printf("%02d/", myRTC.dayOfMonth); Serial.printf("%02d", myRTC.year); From 38d3a2a4cffc9ab96d7b6f62328a3a6d692adb07 Mon Sep 17 00:00:00 2001 From: Adam Date: Wed, 15 Jul 2020 08:54:47 -0400 Subject: [PATCH 46/51] Update RTC.cpp --- libraries/RTC/src/RTC.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libraries/RTC/src/RTC.cpp b/libraries/RTC/src/RTC.cpp index 4a562f94..f824aec7 100644 --- a/libraries/RTC/src/RTC.cpp +++ b/libraries/RTC/src/RTC.cpp @@ -51,8 +51,10 @@ APM3_RTC::APM3_RTC() am_hal_rtc_osc_enable(); } -void APM3_RTC::setTime(uint8_t hund, uint8_t sec, uint8_t min, uint8_t hour, uint8_t dayOfMonth, uint8_t month, uint16_t year) -{ + +// Note: Order of parameters to change in v2.0.0. +void APM3_RTC::setTime(uint8_t hour, uint8_t min, uint8_t sec, uint8_t hund, uint8_t dayOfMonth, uint8_t month, uint16_t year) + hal_time.ui32Weekday = am_util_time_computeDayofWeek(2000 + year, month, dayOfMonth); //computeDayofWeek is expecting 1 to 12 months hal_time.ui32Century = 0; hal_time.ui32Year = year; From a2279edd016caf751b6e57eabaddcc4aa2edf450 Mon Sep 17 00:00:00 2001 From: Adam Date: Wed, 15 Jul 2020 08:54:49 -0400 Subject: [PATCH 47/51] Update RTC.h --- libraries/RTC/src/RTC.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libraries/RTC/src/RTC.h b/libraries/RTC/src/RTC.h index 7e3e2305..6505d4eb 100644 --- a/libraries/RTC/src/RTC.h +++ b/libraries/RTC/src/RTC.h @@ -11,7 +11,8 @@ class APM3_RTC void getTime(); //Query the RTC for the current time/date uint32_t getEpoch(); //Return the current RTC time/date as UNIX Epoch time - void setTime(uint8_t hund, uint8_t sec, uint8_t min, uint8_t hour, uint8_t dayOfMonth, uint8_t month, uint16_t year); //Set current time to provided hundredths/seconds/etc + void setTime(uint8_t hour, uint8_t min, uint8_t sec, uint8_t hund, + uint8_t dayOfMonth, uint8_t month, uint16_t year); //Set current time to provided hundredths/seconds/etc void setToCompilerTime(); //Set to time when sketch was compiled void setEpoch(uint32_t ts); //Set current time to provided UNIX Epoch time From 2656e0794b3e0223e63382491683cf4c5fcb621d Mon Sep 17 00:00:00 2001 From: oclyke Date: Wed, 15 Jul 2020 11:21:06 -0600 Subject: [PATCH 48/51] standardize RTC api for setTime and setAlarm In v1.x.x we are using (hh, mm, ss, hund, dom, mon, year) Planning to change api in v2.0.0 to (hund, mm, ss, hh, dom, mon, year) --- .../RTC/examples/Example1_Get_Time/Example1_Get_Time.ino | 2 +- .../examples/Example2_Set_Alarms/Example2_Set_Alarms.ino | 5 ++--- .../RTC/examples/Example3_Test_RTC/Example3_Test_RTC.ino | 4 ++-- .../Example5_Rolling_Alarms/Example5_Rolling_Alarms.ino | 9 +++++---- .../Example6_LowPower_Alarm/Example6_LowPower_Alarm.ino | 4 ++-- libraries/RTC/src/RTC.cpp | 5 +++-- libraries/RTC/src/RTC.h | 2 +- 7 files changed, 16 insertions(+), 15 deletions(-) diff --git a/libraries/RTC/examples/Example1_Get_Time/Example1_Get_Time.ino b/libraries/RTC/examples/Example1_Get_Time/Example1_Get_Time.ino index 2b489b90..f0aa8607 100644 --- a/libraries/RTC/examples/Example1_Get_Time/Example1_Get_Time.ino +++ b/libraries/RTC/examples/Example1_Get_Time/Example1_Get_Time.ino @@ -25,7 +25,7 @@ void setup() myRTC.setToCompilerTime(); // Manually set RTC date and time - //myRTC.setTime(0, 50, 59, 12, 3, 6, 20); // 12:59:50.000, June 3rd, 2020 (hund, ss, mm, hh, dd, mm, yy) + //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() diff --git a/libraries/RTC/examples/Example2_Set_Alarms/Example2_Set_Alarms.ino b/libraries/RTC/examples/Example2_Set_Alarms/Example2_Set_Alarms.ino index f8ee8308..143585bd 100644 --- a/libraries/RTC/examples/Example2_Set_Alarms/Example2_Set_Alarms.ino +++ b/libraries/RTC/examples/Example2_Set_Alarms/Example2_Set_Alarms.ino @@ -28,11 +28,10 @@ void setup() //myRTC.setToCompilerTime(); // Manually set RTC date and time - myRTC.setTime(0, 50, 59, 12, 3, 6, 20); // 12:59:50.000, June 3rd, 2020 (hund, ss, mm, hh, dd, mm, yy) + 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(0, 0, 0, 13, 3, 6); // 13:00:00.000, June 3rd (hund, ss, mm, hh, dd, mm). Note: No year alarm register - + 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 diff --git a/libraries/RTC/examples/Example3_Test_RTC/Example3_Test_RTC.ino b/libraries/RTC/examples/Example3_Test_RTC/Example3_Test_RTC.ino index e8e69a24..814450d7 100644 --- a/libraries/RTC/examples/Example3_Test_RTC/Example3_Test_RTC.ino +++ b/libraries/RTC/examples/Example3_Test_RTC/Example3_Test_RTC.ino @@ -18,7 +18,7 @@ void setup() Serial.println("Artemis RTC Testing"); // Manually set RTC date and time - myRTC.setTime(0, 59, 59, 23, 1, 1, 20); // Set to 1 second before midnight + myRTC.setTime(23, 59, 59, 0, 1, 1, 20); // Set to 1 second before midnight } void loop() @@ -26,7 +26,7 @@ void loop() printArtemisTime(); myRTC.getTime(); - myRTC.setTime(99, 59, 59, 23, myRTC.dayOfMonth, myRTC.month, myRTC.year); // Manually set RTC + 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 } diff --git a/libraries/RTC/examples/Example5_Rolling_Alarms/Example5_Rolling_Alarms.ino b/libraries/RTC/examples/Example5_Rolling_Alarms/Example5_Rolling_Alarms.ino index 5501e9e6..41bdbd29 100644 --- a/libraries/RTC/examples/Example5_Rolling_Alarms/Example5_Rolling_Alarms.ino +++ b/libraries/RTC/examples/Example5_Rolling_Alarms/Example5_Rolling_Alarms.ino @@ -28,10 +28,10 @@ void setup() //myRTC.setToCompilerTime(); // Manually set RTC date and time - myRTC.setTime(0, 50, 59, 12, 3, 6, 20); // 12:59:50.000, June 3rd, 2020 (hund, ss, mm, hh, dd, mm, yy) + 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(0, 0, 0, 13, 3, 6); // 13:00:00.000, June 3rd (hund, ss, mm, hh, dd, mm). Note: No year alarm register + 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 /* @@ -63,9 +63,10 @@ void loop() alarmFlag = false; // Set the RTC's rolling alarm - myRTC.setAlarm(0, (myRTC.seconds + alarmSeconds) % 60, + myRTC.setAlarm((myRTC.hour + alarmHours) % 24, (myRTC.minute + alarmMinutes) % 60, - (myRTC.hour + alarmHours) % 24, + (myRTC.seconds + alarmSeconds) % 60, + 0, myRTC.dayOfMonth, myRTC.month); myRTC.setAlarmMode(6); diff --git a/libraries/RTC/examples/Example6_LowPower_Alarm/Example6_LowPower_Alarm.ino b/libraries/RTC/examples/Example6_LowPower_Alarm/Example6_LowPower_Alarm.ino index 36433967..fd9efcd3 100644 --- a/libraries/RTC/examples/Example6_LowPower_Alarm/Example6_LowPower_Alarm.ino +++ b/libraries/RTC/examples/Example6_LowPower_Alarm/Example6_LowPower_Alarm.ino @@ -24,10 +24,10 @@ void setup() //myRTC.setToCompilerTime(); // Manually set RTC date and time - myRTC.setTime(0, 50, 59, 12, 3, 6, 20); // 12:59:50.000, June 3rd, 2020 (hund, ss, mm, hh, dd, mm, yy) + 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(0, 0, 0, 13, 3, 6); // 13:00:00.000, June 3rd (hund, ss, mm, hh, dd, mm). Note: No year alarm register + 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 /* diff --git a/libraries/RTC/src/RTC.cpp b/libraries/RTC/src/RTC.cpp index f824aec7..3d0294df 100644 --- a/libraries/RTC/src/RTC.cpp +++ b/libraries/RTC/src/RTC.cpp @@ -54,7 +54,7 @@ APM3_RTC::APM3_RTC() // Note: Order of parameters to change in v2.0.0. void APM3_RTC::setTime(uint8_t hour, uint8_t min, uint8_t sec, uint8_t hund, uint8_t dayOfMonth, uint8_t month, uint16_t year) - +{ hal_time.ui32Weekday = am_util_time_computeDayofWeek(2000 + year, month, dayOfMonth); //computeDayofWeek is expecting 1 to 12 months hal_time.ui32Century = 0; hal_time.ui32Year = year; @@ -157,7 +157,8 @@ void APM3_RTC::getAlarm() alarmHundredths = alm_time.ui32Hundredths; } -void APM3_RTC::setAlarm(uint8_t hund, uint8_t sec, uint8_t min, uint8_t hour, uint8_t dayOfMonth, uint8_t month) +// Note: Order of parameters to change in v2.0.0. +void APM3_RTC::setAlarm(uint8_t hour, uint8_t min, uint8_t sec, uint8_t hund, uint8_t dayOfMonth, uint8_t month) { alm_time.ui32Weekday = 0; // WIP alm_time.ui32Month = month; diff --git a/libraries/RTC/src/RTC.h b/libraries/RTC/src/RTC.h index 6505d4eb..93cede37 100644 --- a/libraries/RTC/src/RTC.h +++ b/libraries/RTC/src/RTC.h @@ -17,7 +17,7 @@ class APM3_RTC void setEpoch(uint32_t ts); //Set current time to provided UNIX Epoch time void getAlarm(); //Query the RTC for the current alarm time/date - void setAlarm(uint8_t hund, uint8_t sec, uint8_t min, uint8_t hour, uint8_t dayOfMonth, uint8_t month); //Set alarm time to provided hundredths/seconds/etc + void setAlarm(uint8_t hour, uint8_t min, uint8_t sec, uint8_t hund, uint8_t dayOfMonth, uint8_t month); //Set alarm time to provided hundredths/seconds/etc void setAlarmMode(uint8_t mode); //Set the RTC alarm repeat interval void attachInterrupt(); //Attach the RTC alarm interrupt void detachInterrupt(); //Detach the RTC alarm interrupt From 751ab8f7c240941ab160d2544922fa20315c1bc3 Mon Sep 17 00:00:00 2001 From: oclyke Date: Wed, 15 Jul 2020 15:51:24 -0600 Subject: [PATCH 49/51] fix Example3 --- .../Example3_Test_RTC/Example3_Test_RTC.ino | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/libraries/RTC/examples/Example3_Test_RTC/Example3_Test_RTC.ino b/libraries/RTC/examples/Example3_Test_RTC/Example3_Test_RTC.ino index 814450d7..0c38a3d9 100644 --- a/libraries/RTC/examples/Example3_Test_RTC/Example3_Test_RTC.ino +++ b/libraries/RTC/examples/Example3_Test_RTC/Example3_Test_RTC.ino @@ -9,7 +9,7 @@ #include "RTC.h" APM3_RTC myRTC; // Create instance of RTC class -int previousDay = 1; +int previousDay; void setup() { @@ -19,15 +19,17 @@ void setup() // Manually set RTC date and time myRTC.setTime(23, 59, 59, 0, 1, 1, 20); // Set to 1 second before midnight + myRTC.getTime(); } void loop() { - printArtemisTime(); - - myRTC.getTime(); myRTC.setTime(23, 59, 59, 99, myRTC.dayOfMonth, myRTC.month, myRTC.year); // Manually set RTC + myRTC.getTime(); + previousDay = myRTC.weekday; delay(11); //Allow us to roll from midnight the night before to the new day + + printArtemisTime(); } void printArtemisTime() @@ -77,7 +79,5 @@ void printArtemisTime() ; } - previousDay = myRTC.weekday; - Serial.println(); -} +} \ No newline at end of file From d3bd83234542f8cb08b812dfb2b093c97c0668f0 Mon Sep 17 00:00:00 2001 From: oclyke Date: Thu, 16 Jul 2020 11:01:10 -0600 Subject: [PATCH 50/51] automatically update internal structures on setTime and setToCompilerTime This allows the user to immediately access correct internal values (myRTC.weekday, myRTC.minute, etc...) ``` myRTC.setTime(23, 59, 59, 99, myRTC.dayOfMonth, myRTC.month, myRTC.year); previousDay = myRTC.weekday; ``` Updated Example3 to make use of this feature --- .../RTC/examples/Example3_Test_RTC/Example3_Test_RTC.ino | 8 +++----- libraries/RTC/src/RTC.cpp | 2 ++ 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/libraries/RTC/examples/Example3_Test_RTC/Example3_Test_RTC.ino b/libraries/RTC/examples/Example3_Test_RTC/Example3_Test_RTC.ino index 0c38a3d9..e47f7cae 100644 --- a/libraries/RTC/examples/Example3_Test_RTC/Example3_Test_RTC.ino +++ b/libraries/RTC/examples/Example3_Test_RTC/Example3_Test_RTC.ino @@ -17,15 +17,13 @@ void setup() delay(10); Serial.println("Artemis RTC Testing"); - // Manually set RTC date and time - myRTC.setTime(23, 59, 59, 0, 1, 1, 20); // Set to 1 second before midnight - myRTC.getTime(); + // Manually set RTC date and time to the start of 2020 so that myRTC contains valid times + myRTC.setTime(23, 59, 59, 0, 1, 1, 20); // Set to 1 second before midnight Jan 1 } void loop() { - myRTC.setTime(23, 59, 59, 99, myRTC.dayOfMonth, myRTC.month, myRTC.year); // Manually set RTC - myRTC.getTime(); + myRTC.setTime(23, 59, 59, 99, myRTC.dayOfMonth, myRTC.month, myRTC.year); // Manually set RTC 1/100th of a second from the next day previousDay = myRTC.weekday; delay(11); //Allow us to roll from midnight the night before to the new day diff --git a/libraries/RTC/src/RTC.cpp b/libraries/RTC/src/RTC.cpp index 3d0294df..c15eec3c 100644 --- a/libraries/RTC/src/RTC.cpp +++ b/libraries/RTC/src/RTC.cpp @@ -66,6 +66,7 @@ void APM3_RTC::setTime(uint8_t hour, uint8_t min, uint8_t sec, uint8_t hund, uin hal_time.ui32Hundredths = hund; am_hal_rtc_time_set(&hal_time); //Initialize the RTC with this date/time + getTime(); } //Takes the time from the last build and uses it as the current time @@ -85,6 +86,7 @@ void APM3_RTC::setToCompilerTime() hal_time.ui32Hundredths = 00; am_hal_rtc_time_set(&hal_time); //Initialize the RTC with this date/time + getTime(); } void APM3_RTC::setEpoch(uint32_t ts) From 0d0b549d3f1d8613ccd9fee7b806c812cbba9359 Mon Sep 17 00:00:00 2001 From: oclyke Date: Thu, 16 Jul 2020 11:02:05 -0600 Subject: [PATCH 51/51] Convert Example2 loop to non-blocking This allows the user to see that the alarm fired 'exactly' when they wanted it to. --- .../examples/Example2_Set_Alarms/Example2_Set_Alarms.ino | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/libraries/RTC/examples/Example2_Set_Alarms/Example2_Set_Alarms.ino b/libraries/RTC/examples/Example2_Set_Alarms/Example2_Set_Alarms.ino index 143585bd..e25ef0ca 100644 --- a/libraries/RTC/examples/Example2_Set_Alarms/Example2_Set_Alarms.ino +++ b/libraries/RTC/examples/Example2_Set_Alarms/Example2_Set_Alarms.ino @@ -63,8 +63,11 @@ void loop() } // Print RTC's date and time while waiting for alarm - printDateTime(); - delay(1000); + static uint32_t nextPrint = 0; + if(millis() > nextPrint){ + printDateTime(); + nextPrint = millis() + 1000; + } } // Print the RTC's current date and time