Skip to content

Commit ca0911e

Browse files
committed
Add new example using alarm data callback
Add advancedRTCAlarm example using data callback to reload alarm. So, alarm will match indefinitely. Fix also warning in simpleRTCAlarm. Signed-off-by: Frederic.Pillon <[email protected]>
1 parent e7aefb8 commit ca0911e

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
advancedRTCAlarm
3+
4+
This sketch is an extension of simpleRTCAlarm.
5+
It uses the optional 'data' alarm callback parameters to
6+
reload alarm with 'atime' offset indefinitely.
7+
8+
9+
Creation 25 May 2018
10+
by Frederic Pillon for STMicroelectronics
11+
12+
This example code is in the public domain.
13+
14+
https://github.com/stm32duino/STM32RTC
15+
16+
*/
17+
18+
#include <STM32RTC.h>
19+
20+
/* Get the rtc object */
21+
STM32RTC& rtc = STM32RTC::getInstance();
22+
23+
/* Declare it volatile since it's incremented inside an interrupt */
24+
volatile int alarmMatch_counter = 0;
25+
26+
/* Change this value to set alarm match offset */
27+
static uint32_t atime = 5;
28+
29+
/* Change these values to set the current initial time */
30+
const byte seconds = 0;
31+
const byte minutes = 0;
32+
const byte hours = 16;
33+
34+
/* Change these values to set the current initial date */
35+
const byte day = 25;
36+
const byte month = 9;
37+
const byte year = 15;
38+
39+
void setup()
40+
{
41+
Serial.begin(9600);
42+
43+
rtc.begin(); // initialize RTC 24H format
44+
45+
rtc.setTime(hours, minutes, seconds);
46+
rtc.setDate(day, month, year);
47+
48+
rtc.attachInterrupt(alarmMatch, &atime);
49+
rtc.setAlarmDay(day);
50+
rtc.setAlarmTime(16, 0, 10);
51+
rtc.enableAlarm(rtc.MATCH_DHHMMSS);
52+
}
53+
54+
void loop()
55+
{
56+
57+
}
58+
59+
void alarmMatch(void *data)
60+
{
61+
uint32_t sec = 1;
62+
if(data != NULL) {
63+
sec = *(uint32_t*)data;
64+
// Minimum is 1 second
65+
if (sec == 0){
66+
sec = 1;
67+
}
68+
}
69+
alarmMatch_counter++;
70+
Serial.print("Alarm Match ");
71+
Serial.println(alarmMatch_counter);
72+
rtc.setAlarmEpoch( rtc.getEpoch() + sec);
73+
}

examples/simpleRTCAlarm/simpleRTCAlarm.ino

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,5 +73,6 @@ void loop()
7373

7474
void alarmMatch(void *data)
7575
{
76+
UNUSED(data);
7677
Serial.println("Alarm Match!");
7778
}

0 commit comments

Comments
 (0)