1
1
/*
2
- AdvancedTimedWakeup
2
+ AlarmTimedWakeup
3
3
4
- This sketch demonstrates the usage of Internal Interrupts to wakeup a chip in deep sleep mode.
4
+ This sketch demonstrates the usage of Internal Interrupts to wakeup a chip in deep sleep mode,
5
+ when the RTC is configured in BCD or MIX mode (BCD and BINARY)
5
6
6
7
In this sketch:
8
+ - RTC is configured in BCD (default) or MIX mode (BCD and BINARY)
7
9
- RTC date and time are configured.
8
10
- Alarm is set to wake up the processor each 'atime' and called a custom alarm callback
9
11
which increment a value and reload alarm with 'atime' offset.
@@ -19,7 +21,7 @@ STM32RTC& rtc = STM32RTC::getInstance();
19
21
20
22
/* Change this value to set alarm match offset in millisecond */
21
23
/* Note that STM32F1xx does not manage subsecond only second */
22
- static uint32_t atime = 567 ;
24
+ static uint32_t atime = 600 ;
23
25
24
26
// Declare it volatile since it's incremented inside an interrupt
25
27
volatile int alarmMatch_counter = 0 ;
@@ -35,21 +37,32 @@ static byte month = 1;
35
37
static byte year = 18 ;
36
38
37
39
void setup () {
40
+ #if defined(RTC_BINARY_NONE)
41
+ // Select RTC clock source: LSI_CLOCK, LSE_CLOCK or HSE_CLOCK.
42
+ // By default the LSI is selected as source.
43
+ // rtc.setClockSource(STM32RTC::LSE_CLOCK);
44
+ // Select the STM32RTC::MODE_BCD or STM32RTC::MODE_MIX
45
+ // By default the STM32RTC::MODE_BCD is selected.
46
+ // rtc.setBinaryMode(STM32RTC::MODE_BCD);
47
+ rtc.begin (true ); /* reset the RTC else the binary mode is not changed */
48
+ #else
38
49
rtc.begin ();
50
+ #endif /* RTC_BINARY_NONE */
39
51
rtc.setTime (hours, minutes, seconds);
40
52
rtc.setDate (weekDay, day, month, year);
41
53
42
54
pinMode (LED_BUILTIN, OUTPUT);
43
55
44
- Serial.begin (9600 );
56
+ Serial.begin (115200 );
45
57
while (!Serial) {}
58
+ Serial.println (" Start !" );
46
59
47
60
// Configure low power
48
61
LowPower.begin ();
49
62
LowPower.enableWakeupFrom (&rtc, alarmMatch, &atime);
50
63
51
64
// Configure first alarm in 2 second then it will be done in the rtc callback
52
- rtc.setAlarmEpoch ( rtc.getEpoch () + 2 );
65
+ rtc.setAlarmEpoch (rtc.getEpoch () + 2 );
53
66
}
54
67
55
68
void loop () {
@@ -63,8 +76,7 @@ void loop() {
63
76
LowPower.deepSleep ();
64
77
}
65
78
66
- void alarmMatch (void * data)
67
- {
79
+ void alarmMatch (void * data) {
68
80
// This function will be called once on device wakeup
69
81
// You can do some little operations here (like changing variables which will be used in the loop)
70
82
// Remember to avoid calling delay() and long running functions since this functions executes in interrupt context
@@ -91,7 +103,7 @@ void alarmMatch(void* data)
91
103
// Update epoch_ms - might need to add a second to epoch
92
104
epoc_ms += _millis;
93
105
if (epoc_ms >= 1000 ) {
94
- sec ++;
106
+ sec++;
95
107
epoc_ms -= 1000 ;
96
108
}
97
109
#endif
0 commit comments