Skip to content

Commit d5484bb

Browse files
fpistmbatkov
andcommitted
feat: add second alarm (B) support
Fixes #74 Signed-off-by: Frederic Pillon <frederic.pillon@st.com> Co-authored-by: hariton_batkov <yanker90@gmail.com>
1 parent 718e96a commit d5484bb

File tree

7 files changed

+564
-127
lines changed

7 files changed

+564
-127
lines changed

README.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ _SubSeconds alarm management_
7272
* **`void setAlarmTime(uint8_t hours, uint8_t minutes, uint8_t seconds, uint32_t subSeconds = 0, AM_PM period = AM)`**
7373
* **`uint32_t getEpoch(uint32_t *subSeconds = nullptr)`**
7474
* **`void setEpoch(uint32_t ts, uint32_t subSeconds = 0)`**
75-
* **`void setAlarmEpoch(uint32_t ts, Alarm_Match match = MATCH_DHHMMSS, uint32_t subSeconds = 0)`**
75+
* **`void setAlarmEpoch(uint32_t ts, Alarm_Match match = MATCH_DHHMMSS, uint32_t subSeconds = 0)`**
7676

7777
_Library version management_
7878

@@ -105,7 +105,7 @@ _Library version management_
105105
_One-Second interrupt_
106106

107107
STM32 RTC includes a one-second interrupt for generating a periodic interrupt signal.
108-
- This feature is native on the stm32F1xx and mapped on the existing WakeUp interrupt on other stm32 mcus.
108+
- This feature is native on the stm32F1xx and mapped on the existing WakeUp interrupt on other stm32 mcus.
109109
- It is not available on some stm32F0 devices.
110110

111111
* **new API:**
@@ -138,6 +138,21 @@ To know if a time has already been set use:
138138
}
139139
```
140140
141+
### Since STM32RTC version higher than 1.3.4
142+
_Second alarm (Alarm B)_
143+
144+
Some STM32 RTC have a second alarm named `RTC_ALARM_B`.
145+
It is possible to use it thanks all alarm API with an extra argument:
146+
- `STM32RTC::ALARM_A`
147+
- `STM32RTC::ALARM_B`
148+
149+
```C++
150+
rtc.attachInterrupt(myCallback, &myCallbackdata, STM32RTC::ALARM_B);
151+
rtc.setAlarmDay(day, STM32RTC::ALARM_B);
152+
rtc.setAlarmTime(hours, minutes, seconds + 5, 567, STM32RTC::ALARM_B);
153+
rtc.enableAlarm(rtc.MATCH_DHHMMSS, STM32RTC::ALARM_B);
154+
```
155+
141156
Refer to the Arduino RTC documentation for the other functions
142157
http://arduino.cc/en/Reference/RTC
143158

examples/advancedRTCAlarm/advancedRTCAlarm.ino

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
It uses the optional 'data' alarm callback parameters to
66
reload alarm with 'atime' offset indefinitely.
77
8+
If a second alarm (B) is available, it is configured
9+
to trigger each second.
10+
811
Creation 25 May 2018
912
by Frederic Pillon for STMicroelectronics
1013
Modified 03 Jul 2020
@@ -22,6 +25,9 @@ STM32RTC& rtc = STM32RTC::getInstance();
2225

2326
/* Declare it volatile since it's incremented inside an interrupt */
2427
volatile int alarmMatch_counter = 0;
28+
#ifdef RTC_ALARM_B
29+
volatile int alarmBMatch_counter = 0;
30+
#endif
2531

2632
/* Change this value to set alarm match offset in millisecond */
2733
/* Note that STM32F1xx does not manage subsecond only second */
@@ -54,6 +60,13 @@ void setup()
5460
rtc.setAlarmDay(day);
5561
rtc.setAlarmTime(16, 0, 10, 567);
5662
rtc.enableAlarm(rtc.MATCH_DHHMMSS);
63+
64+
#ifdef RTC_ALARM_B
65+
rtc.attachInterrupt(alarmBMatch, STM32RTC::ALARM_B);
66+
rtc.setAlarmDay(day, STM32RTC::ALARM_B);
67+
rtc.setAlarmTime(16, 0, 11, 567, STM32RTC::ALARM_B);
68+
rtc.enableAlarm(rtc.MATCH_DHHMMSS, STM32RTC::ALARM_B);
69+
#endif
5770
}
5871

5972
void loop()
@@ -97,3 +110,12 @@ void alarmMatch(void *data)
97110
Serial.printf("Alarm Match %i\n", ++alarmMatch_counter);
98111
rtc.setAlarmEpoch(epoc + sec, STM32RTC::MATCH_SS, epoc_ms);
99112
}
113+
114+
#ifdef RTC_ALARM_B
115+
void alarmBMatch(void *data)
116+
{
117+
(void)data;
118+
Serial.printf("Alarm B Match %i\n", ++alarmBMatch_counter);
119+
rtc.setAlarmEpoch(rtc.getEpoch() + 2, STM32RTC::MATCH_SS, STM32RTC::ALARM_B);
120+
}
121+
#endif

keywords.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,5 @@ PM LITERAL1
9797
LSE_CLOCK LITERAL1
9898
LSI_CLOCK LITERAL1
9999
HSE_CLOCK LITERAL1
100+
ALARM_A LITERAL1
101+
ALARM_B LITERAL1

0 commit comments

Comments
 (0)