11/*
2- AdvancedTimedWakeup
2+ AlarmTimedWakeup
33
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)
56
67 In this sketch:
8+ - RTC is configured in BCD (default) or MIX mode (BCD and BINARY)
79 - RTC date and time are configured.
810 - Alarm is set to wake up the processor each 'atime' and called a custom alarm callback
911 which increment a value and reload alarm with 'atime' offset.
@@ -19,7 +21,7 @@ STM32RTC& rtc = STM32RTC::getInstance();
1921
2022/* Change this value to set alarm match offset in millisecond */
2123/* Note that STM32F1xx does not manage subsecond only second */
22- static uint32_t atime = 567 ;
24+ static uint32_t atime = 600 ;
2325
2426// Declare it volatile since it's incremented inside an interrupt
2527volatile int alarmMatch_counter = 0 ;
@@ -35,21 +37,32 @@ static byte month = 1;
3537static byte year = 18 ;
3638
3739void 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
3849 rtc.begin ();
50+ #endif /* RTC_BINARY_NONE */
3951 rtc.setTime (hours, minutes, seconds);
4052 rtc.setDate (weekDay, day, month, year);
4153
4254 pinMode (LED_BUILTIN, OUTPUT);
4355
44- Serial.begin (9600 );
56+ Serial.begin (115200 );
4557 while (!Serial) {}
58+ Serial.println (" Start !" );
4659
4760 // Configure low power
4861 LowPower.begin ();
4962 LowPower.enableWakeupFrom (&rtc, alarmMatch, &atime);
5063
5164 // 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 );
5366}
5467
5568void loop () {
@@ -63,8 +76,7 @@ void loop() {
6376 LowPower.deepSleep ();
6477}
6578
66- void alarmMatch (void * data)
67- {
79+ void alarmMatch (void * data) {
6880 // This function will be called once on device wakeup
6981 // You can do some little operations here (like changing variables which will be used in the loop)
7082 // Remember to avoid calling delay() and long running functions since this functions executes in interrupt context
@@ -91,7 +103,7 @@ void alarmMatch(void* data)
91103 // Update epoch_ms - might need to add a second to epoch
92104 epoc_ms += _millis;
93105 if (epoc_ms >= 1000 ) {
94- sec ++;
106+ sec++;
95107 epoc_ms -= 1000 ;
96108 }
97109#endif
0 commit comments