Skip to content

Commit 44f5e5f

Browse files
authored
Merge pull request #25 from FRASTM/millisec_rtc_mix
Use the RTC in MIX mode and convert timeout values
2 parents aef56fd + 365fb83 commit 44f5e5f

File tree

16 files changed

+125
-372
lines changed

16 files changed

+125
-372
lines changed

.github/workflows/check-astyle.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ jobs:
1313
steps:
1414
- run: sudo apt install astyle
1515
- uses: actions/checkout@v3
16-
- run: astyle --project=.astylerc --recursive '*.c' '*.h' '*.ino'
16+
- run: astyle --project=.astylerc --recursive '*.c' '*.h'
1717
# If anything changed, this will fail and show the needed changes
1818
- run: git diff --exit-code

docs/overview.md

+2-6
Original file line numberDiff line numberDiff line change
@@ -243,12 +243,8 @@ This library makes use of:
243243
- The radio module, obviously. The library handles enabling the module
244244
and the associated SPI block, so nothing is needed in the sketch.
245245

246-
- The RTC for timing. This library currently completely configures the
247-
RTC and defines the interrupt handler, making it impossible to use
248-
the RTC for anything else. In the future, this library could be
249-
modified to co-exist with e.g. the STM32RTC library or use
250-
a (low-power) timer instead of the RTC, but this is not possible
251-
right now.
246+
- The RTC for timing (Since v0.2.0). This library uses the
247+
[STM32RTC library](https://github.com/stm32duino/STM32RTC).
252248

253249
- A number of GPIO pins that are connected to external RF circuitry on
254250
the board. This just uses the Arduino `digitalWrite()` functions.

examples/Basic/Basic.ino

+20-10
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* This is a very basic example that demonstrates how to configure the
33
* library, join the network, send regular packets and print any
44
* downlink packets received.
5+
* This example is using the RTC in MIX (binary and BCD) mode
56
*
67
* Revised BSD License - https://spdx.org/licenses/BSD-3-Clause.html
78
*/
@@ -12,8 +13,10 @@ STM32LoRaWAN modem;
1213
static const unsigned long TX_INTERVAL = 60000; /* ms */
1314
unsigned long last_tx = 0;
1415

15-
void setup()
16-
{
16+
/* Get the rtc object */
17+
STM32RTC& rtc = STM32RTC::getInstance();
18+
19+
void setup() {
1720
Serial.begin(115200);
1821
Serial.println("Start");
1922
modem.begin(EU868);
@@ -27,17 +30,25 @@ void setup()
2730
Serial.println("Joined");
2831
} else {
2932
Serial.println("Join failed");
30-
while (true) /* infinite loop */;
33+
while (true) /* infinite loop */
34+
;
3135
}
36+
37+
/* set the calendar */
38+
rtc.setTime(15, 30, 58);
39+
rtc.setDate(04, 07, 23);
3240
}
3341

34-
void send_packet()
35-
{
36-
uint8_t payload[] = {0xde, 0xad, 0xbe, 0xef};
42+
void send_packet() {
43+
char payload[27] = { 0 }; /* packet to be sent */
44+
/* prepare the Tx packet : get date and format string */
45+
sprintf(payload, "%02d/%02d/%04d - %02d:%02d:%02d",
46+
rtc.getMonth(), rtc.getDay(), 2000 + rtc.getYear(),
47+
rtc.getHours(), rtc.getMinutes(), rtc.getSeconds());
3748
modem.setPort(10);
3849
modem.beginPacket();
39-
modem.write(payload, sizeof(payload));
40-
if (modem.endPacket() == sizeof(payload)) {
50+
modem.write(payload, strlen(payload));
51+
if (modem.endPacket() == (int)strlen(payload)) {
4152
Serial.println("Sent packet");
4253
} else {
4354
Serial.println("Failed to send packet");
@@ -57,8 +68,7 @@ void send_packet()
5768
}
5869
}
5970

60-
void loop()
61-
{
71+
void loop() {
6272
if (!last_tx || millis() - last_tx > TX_INTERVAL) {
6373
send_packet();
6474
last_tx = millis();

examples/ScheduledAsync/ScheduledAsync.ino

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ void do_blink()
7272
}
7373

7474
/*********************************************************************
75-
* This part of the sketch defines the lora work task, which iniates new
76-
* work and the lora_done() function that processes the results.
75+
* This part of the sketch defines the lora work task, which initiates
76+
* new work and the lora_done() function that processes the results.
7777
*********************************************************************/
7878

7979
static const unsigned long TX_INTERVAL = 60000; /* ms */

library.properties

+1
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ paragraph=Provides APIs to communicate with LoRa® and LoraWAN® networks
77
category=Communication
88
url=https://github.com/stm32duino/STM32LoRaWAN
99
architectures=stm32
10+
depends=STM32duino RTC

src/BSP/main.h

-50
This file was deleted.

src/BSP/rtc.c

-156
This file was deleted.

src/BSP/rtc.h

-53
This file was deleted.

0 commit comments

Comments
 (0)