It took a lot of time for trying, testing, debugging, but finally I managed to create a plain and simple LoraWan LowPower Library for STM32. Especially for the STM32L051C8T6 microcontroller in an example project.
Based on the MiniPill LoRa board the sleep current is reduces to 1.4 uA and this current is also drawn during RX1_delay and RX2_delay and RX1_join_delay. So minimal power is used during lifetime.
The other feature is that the code does not use Real Time OS like the LMIC code. Just straight Arduino (OOP) code. And many comments are added to explain the working and functions of the code.
The code is now under long term testing with CR2032 and LR44 batteries. You will get this information as soon as it is available.
Battery tests
As promised, here are the results of the first tests with this library. Al tests are done under this condition:
- every 5 minutes sending data uplink (Vcc, temperature, humidity, pressure) 8 data bytes
- no downlink data send
- In-house conditions (about 15-30 degrees celcius)
- Pressure near sea level (The Netherlands)
Date in | Battery | Time lived | Remark |
05-12-2022 | 2x LR44 (brand: Hema (dutch)) | (24-06-2023) 201 days | TTN05 node |
04-12-2022 | 1x CR2032 (brand: A-force) | (29-04-2023) 146 days | TTN12 node |
19-12-2023 | 1x CR2023 (brand: A-force) | (13-07-2023) 206 days | TTN08 node, with 470uF capacitor over battery |
It seems that adding a capacitor the battery life is extended. I have added this capacitor due to a previous design with an ATtiny84 microcontroller where the capacitor was included. When I have more data available I will update this table.
Timing
Due to the fact that there is no crystal used for both system clock and RTC, there is a slight problem on getting the timing correct in sleep mode. In this mode the RTC clock is used to wake up again. Due to the LoRa protocol you have to wake up after 1 or 5 seconds (RX1/RX2 window and RX1_Join and RX2_Join window) and this time must me quite precise.
To solve this problem I programmed a Wrapper for the STM32LowPower library called STM32LowPowerCal. This wrapper library allows you to calibrate the RTC timer with the higher speed internal system clock. I’ve tested this with 5 different MiniPill boards and it worked!. You have also the possibility to correct this calibration if it is not correct for your board.
Debugging
With this new code and in this example board it is easy to debug. All output is send to the serial port uart2 at 9600 baud. You can enable low-level debugging so you can see LoRaWAN in action while you are testing. The Nordic Power Profiler Kit II was a great help in debugging and to check and set the timing parameters for this project.
Downlink
You can receive downlink messages with this code, and simple ADR messages are replied. Not all ADR messages are implemented, but the most basic is.
Program Flow
Here I show the flow diagram of the example projects. Check out the calibration phase after booting this device.
Example Projects with PSLL
Here are the two example projects. The first one is plain without sensor, just sending static data. The second one is an example with BME280 sensor.
- https://gitlab.com/iot-lab-org/minipill_lora_psll_example_project
- https://gitlab.com/iot-lab-org/minipill-lora-psll-bme280-example-project
Additional information
This is the repository for adding the STM32L051/STM32L151 MiniPill LoRa board and link to the MiniPill LoRa board article.