2
2
Author: Adam Garbo and Nathan Seidle
3
3
Created: June 3rdrd, 2020
4
4
5
- This example demonstrates how to read and set rolling RTC alarms. Each time
6
- the alarm triggers, a user-specified additional amount of time (seconds,
7
- minutes or hours) can be added to create a rolling RTC alarm. Second,
5
+ This example demonstrates how to read and set rolling RTC alarms. Each time
6
+ the alarm triggers, a user-specified additional amount of time (seconds,
7
+ minutes or hours) can be added to create a rolling RTC alarm. Second,
8
8
minute and hour rollovers are handled using modulo calculations.
9
9
10
- The current code is configured as a 5-second rolling RTC alarm.
10
+ The current code is configured as a 5-second rolling RTC alarm.
11
11
*/
12
12
13
- /*
14
- // This file is subject to the terms and conditions defined in
15
- // file 'LICENSE.md', which is part of this source code package.
13
+ /*
14
+ // This file is subject to the terms and conditions defined in
15
+ // file 'LICENSE.md', which is part of this source code package.
16
16
*/
17
17
18
18
#include " RTC.h"
@@ -31,10 +31,10 @@ void setup()
31
31
// RTC.setToCompilerTime();
32
32
33
33
// Manually set RTC date and time
34
- RTC .setTime (0 , 50 , 59 , 12 , 3 , 6 , 20 ); // 12:59:50.000, June 3rd, 2020 (hund, ss, mm, hh, dd, mm, yy)
34
+ rtc .setTime (0 , 50 , 59 , 12 , 3 , 6 , 20 ); // 12:59:50.000, June 3rd, 2020 (hund, ss, mm, hh, dd, mm, yy)
35
35
36
36
// Set the RTC's alarm
37
- RTC .setAlarm (0 , 0 , 0 , 13 , 3 , 6 ); // 13:00:00.000, June 3rd (hund, ss, mm, hh, dd, mm). Note: No year alarm register
37
+ rtc .setAlarm (0 , 0 , 0 , 13 , 3 , 6 ); // 13:00:00.000, June 3rd (hund, ss, mm, hh, dd, mm). Note: No year alarm register
38
38
39
39
// Set the RTC alarm mode
40
40
/*
@@ -47,8 +47,8 @@ void setup()
47
47
6: Alarm match every minute (hundredths, seconds)
48
48
7: Alarm match every second (hundredths)
49
49
*/
50
- RTC .setAlarmMode (6 ); // Set the RTC alarm to match on minutes rollover
51
- RTC .attachInterrupt (); // Attach RTC alarm interrupt
50
+ rtc .setAlarmMode (6 ); // Set the RTC alarm to match on minutes rollover
51
+ rtc .attachInterrupt (); // Attach RTC alarm interrupt
52
52
53
53
// Print the RTC's alarm date and time
54
54
Serial.print (" Next alarm: " ); printAlarm ();
@@ -66,13 +66,13 @@ void loop()
66
66
alarmFlag = false ;
67
67
68
68
// Set the RTC's rolling alarm
69
- RTC .setAlarm (0 ,
70
- (RTC .seconds + alarmSeconds) % 60 ,
71
- (RTC .minute + alarmMinutes) % 60 ,
72
- (RTC .hour + alarmHours) % 24 ,
73
- RTC .dayOfMonth ,
74
- RTC .month );
75
- RTC .setAlarmMode (6 );
69
+ rtc .setAlarm (0 ,
70
+ (rtc .seconds + alarmSeconds) % 60 ,
71
+ (rtc .minute + alarmMinutes) % 60 ,
72
+ (rtc .hour + alarmHours) % 24 ,
73
+ rtc .dayOfMonth ,
74
+ rtc .month );
75
+ rtc .setAlarmMode (6 );
76
76
77
77
// Print next RTC alarm date and time
78
78
Serial.print (" Next rolling alarm: " ); printAlarm ();
@@ -82,31 +82,29 @@ void loop()
82
82
// Print the RTC's current date and time
83
83
void printDateTime ()
84
84
{
85
- RTC.getTime ();
86
- char dateTimeBuffer[25 ];
87
- sprintf (dateTimeBuffer, " 20%02d-%02d-%02d %02d:%02d:%02d.%03d" ,
88
- RTC.year , RTC.month , RTC.dayOfMonth ,
89
- RTC.hour , RTC.minute , RTC.seconds , RTC.hundredths );
90
- Serial.println (dateTimeBuffer);
85
+ rtc.getTime ();
86
+ Serial.printf (" 20%02d-%02d-%02d %02d:%02d:%02d.%03d\n " ,
87
+ rtc.year , rtc.month , rtc.dayOfMonth ,
88
+ rtc.hour , rtc.minute , rtc.seconds , rtc.hundredths );
89
+ Serial.println ();
91
90
}
92
91
93
92
// Print the RTC's alarm
94
93
void printAlarm ()
95
94
{
96
- RTC.getAlarm ();
97
- char alarmBuffer[25 ];
98
- sprintf (alarmBuffer, " 2020-%02d-%02d %02d:%02d:%02d.%03d" ,
99
- RTC.alarmMonth , RTC.alarmDayOfMonth ,
100
- RTC.alarmHour , RTC.alarmMinute ,
101
- RTC.alarmSeconds , RTC.alarmHundredths );
102
- Serial.println (alarmBuffer);
95
+ rtc.getAlarm ();
96
+ Serial.printf (" 2020-%02d-%02d %02d:%02d:%02d.%03d\n " ,
97
+ rtc.alarmMonth , rtc.alarmDayOfMonth ,
98
+ rtc.alarmHour , rtc.alarmMinute ,
99
+ rtc.alarmSeconds , rtc.alarmHundredths );
100
+ Serial.println ();
103
101
}
104
102
105
103
// Interrupt handler for the RTC
106
104
extern " C" void am_rtc_isr (void )
107
105
{
108
106
// Clear the RTC alarm interrupt.
109
- am_hal_rtc_int_clear (AM_HAL_RTC_INT_ALM );
107
+ rtc. clearInterrupt ( );
110
108
111
109
// Set alarm flag
112
110
alarmFlag = true ;
0 commit comments