Skip to content

Commit

Permalink
Change the example to configure RTC alarm in MIX mode
Browse files Browse the repository at this point in the history
In this sketch the RTC is configured in BCD or MIX mode
(for the stm32 devices that supports it)
An Alarm A is set to wakeup the system from low power
deep sleep.

Signed-off-by: Francois Ramu <francois.ramu@st.com>
  • Loading branch information
FRASTM committed Sep 29, 2023
1 parent 5ae219c commit 1dd547b
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions examples/AlarmTimedWakeup/AlarmTimedWakeup.ino
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
/*
AdvancedTimedWakeup
AlarmTimedWakeup
This sketch demonstrates the usage of Internal Interrupts to wakeup a chip in deep sleep mode.
In this sketch:
- RTC is configured in BCD (default) or MIX mode (BCD and BINARY)
- RTC date and time are configured.
- Alarm is set to wake up the processor each 'atime' and called a custom alarm callback
which increment a value and reload alarm with 'atime' offset.
Expand All @@ -19,7 +20,7 @@ STM32RTC& rtc = STM32RTC::getInstance();

/* Change this value to set alarm match offset in millisecond */
/* Note that STM32F1xx does not manage subsecond only second */
static uint32_t atime = 567;
static uint32_t atime = 600;

// Declare it volatile since it's incremented inside an interrupt
volatile int alarmMatch_counter = 0;
Expand All @@ -35,21 +36,30 @@ static byte month = 1;
static byte year = 18;

void setup() {
#if defined(RTC_BINARY_NONE)
// Select RTC clock source: LSI_CLOCK, LSE_CLOCK or HSE_CLOCK.
rtc.setClockSource(STM32RTC::LSE_CLOCK);
// Select the STM32RTC::MODE_BCD or STM32RTC::MODE_MIX
rtc.setBinaryMode(STM32RTC::MODE_BCD);
rtc.begin(true); /* reset the RTC else the binary mode is not changed */
#else
rtc.begin();
#endif /* RTC_BINARY_NONE */
rtc.setTime(hours, minutes, seconds);
rtc.setDate(weekDay, day, month, year);

pinMode(LED_BUILTIN, OUTPUT);

Serial.begin(9600);
Serial.begin(115200);
while (!Serial) {}
Serial.println(" Start !");

// Configure low power
LowPower.begin();
LowPower.enableWakeupFrom(&rtc, alarmMatch, &atime);

// Configure first alarm in 2 second then it will be done in the rtc callback
rtc.setAlarmEpoch( rtc.getEpoch() + 2);
rtc.setAlarmEpoch(rtc.getEpoch() + 2);
}

void loop() {
Expand Down

0 comments on commit 1dd547b

Please sign in to comment.