Skip to content

Commit 1ad5e0b

Browse files
fixed remaining RTC issues
1 parent 59d306f commit 1ad5e0b

File tree

2 files changed

+46
-28
lines changed

2 files changed

+46
-28
lines changed

examples/WakeFromRTC/WakeFromRTC.ino

Lines changed: 44 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,42 +4,67 @@
44
#include "Arduino_Portenta_C33_LowPower.h"
55

66
LowPower lowPower;
7-
8-
97
RTCTime initialTime(1, Month::JANUARY, 2000, 12, 10, 00, DayOfWeek::TUESDAY, SaveLight::SAVING_TIME_ACTIVE);
108

119

1210
void alarmCallback()
1311
{
14-
digitalWrite(LED_BUILTIN, LOW);
15-
delay(1000);
1612
digitalWrite(LED_BUILTIN, HIGH);
17-
lowPower.deepSleep();
13+
delay(1000);
14+
digitalWrite(LED_BUILTIN, LOW);
15+
lowPower.deepSleep();
16+
}
17+
18+
19+
bool sleepFor(int hours, int minutes, int seconds){
20+
{
21+
22+
RTCTime currentTime;
23+
if (!RTC.getTime(currentTime)) {
24+
Serial.println("Failed to get current time");
25+
return false; // Failed to get current time
26+
}
27+
Serial.println(currentTime.toString());
28+
29+
// Convert current time to UNIX timestamp and add the desired interval
30+
time_t currentTimestamp = currentTime.getUnixTime();
31+
currentTimestamp += hours * 3600 + minutes * 60 + seconds;
32+
// Convert back to RTCTime
33+
RTCTime alarmTime(currentTimestamp);
34+
// Configure the alarm match criteria
35+
AlarmMatch match;
36+
match.addMatchSecond(); // Trigger the alarm when the seconds match
37+
match.addMatchMinute(); // Trigger the alarm when the minutes match
38+
match.addMatchHour(); // Trigger the alarm when the hours match
39+
// Set the alarm callback (assuming you have a callback function named alarmCallback)
40+
if (!RTC.setAlarmCallback(alarmCallback, alarmTime, match)) {
41+
Serial.println("Failed to set the alarm");
42+
return false; // Failed to set the alarm
43+
}
44+
45+
// Enable the alarm
46+
Serial.println("Enabling the alarm");
47+
return true;
48+
}
1849
}
1950

2051

2152
void setup(){
53+
Serial.begin(9600);
54+
//while(!Serial);
55+
2256
lowPower = LowPower();
23-
// lowPower.enableWakeupFromRTC(&initialTime, &callback);
2457
lowPower.enableWakeupFromRTC();
2558

2659
pinMode(LED_BUILTIN, OUTPUT);
27-
digitalWrite(LED_BUILTIN, HIGH);
60+
digitalWrite(LED_BUILTIN, LOW);
2861

2962
RTC.begin();
3063

31-
if (!RTC.isRunning()) RTC.setTime(initialTime);
32-
33-
// Trigger the alarm every time the seconds are zero
34-
RTCTime alarmTime;
35-
alarmTime.setSecond(0);
36-
37-
// Make sure to only match on the seconds in this example - not on any other parts of the date/time
38-
AlarmMatch matchTime;
39-
matchTime.addMatchSecond();
40-
41-
//sets the alarm callback
42-
RTC.setAlarmCallback(alarmCallback, alarmTime, matchTime);
64+
if (!RTC.isRunning()) {
65+
RTC.setTime(initialTime);
66+
sleepFor(0, 0, 1);
67+
}
4368

4469
}
4570

src/Arduino_Portenta_C33_LowPower.cpp

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,8 @@ void LowPower::deepSleep(){
2424
}
2525

2626
void LowPower::enableWakeupFromRTC(){
27-
if(deepSleepWakeupSource == 0)
28-
deepSleepWakeupSource = LPM_DEEP_STANDBY_CANCEL_SOURCE_RTC_ALARM;
29-
else
30-
deepSleepWakeupSource = deepSleepWakeupSource | LPM_DEEP_STANDBY_CANCEL_SOURCE_RTC_ALARM;
31-
32-
if(standbyWakeupSource == 0)
33-
standbyWakeupSource = LPM_STANDBY_WAKE_SOURCE_RTCALM;
34-
else
35-
standbyWakeupSource = standbyWakeupSource | LPM_STANDBY_WAKE_SOURCE_RTCALM;
27+
RenesasLowPowerConfig.deep_standby_cancel_source = LPM_DEEP_STANDBY_CANCEL_SOURCE_RTC_ALARM;
28+
RenesasLowPowerConfig.standby_wake_sources = LPM_STANDBY_WAKE_SOURCE_RTCALM;
3629
}
3730

3831
bool LowPower::enableWakeupFromPin(uint8_t pin, PinStatus direction){

0 commit comments

Comments
 (0)