Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the RTC in MIX mode and convert timeout values #25

Merged
merged 11 commits into from
Oct 12, 2023

Conversation

FRASTM
Copy link
Contributor

@FRASTM FRASTM commented Jul 11, 2023

When the RTC is using subsecond as a nb of milliseconds (cf PR stm32duino/STM32RTC#95)

The LoraWan is always using timeout values as a nb of ticks
Ticks is the RTC count unit when running in BINATY or MIX mode to be 1000ms/fqce_apre = 1000 / 256 ~ 3.9ms when the RTC is clocked by the LSE (32768Hz)
fqce_apre = LSE clock/ (Async prediv + 1)

Setting the Lorawan alarm (ALARM B) to expire in a nb of ticks, requires a conversion to when the RTC_StartAlarm() has a subsecond parameter expressed in milliseconds :
Timeout in milliseconds = timeout in ticks * 1000 / 256 ( + 1 to compensate division uncertainty)

Requires RTC stm32duino/STM32RTC#95

Fixes #9

@FRASTM
Copy link
Contributor Author

FRASTM commented Sep 1, 2023

Adding another commit with a new sketch to send the current calendar on LoRa

@FRASTM
Copy link
Contributor Author

FRASTM commented Sep 5, 2023

Calculate the ck_apre from the RTC clock source and the Async prescaler (prediv_A )
ck_apre = RTC_clock / (prediv_A +1) given by the ref Manual.
This is 256 when LSE clock and prediv_A = 0x7F (default)

@FRASTM FRASTM marked this pull request as ready for review September 6, 2023 07:11
@FRASTM FRASTM force-pushed the millisec_rtc_mix branch 2 times, most recently from c44652e to 9366b63 Compare September 11, 2023 15:17
@fpistm fpistm force-pushed the millisec_rtc_mix branch 3 times, most recently from 5a76db6 to 01be423 Compare September 22, 2023 14:30
@fpistm fpistm added the enhancement New feature or request label Sep 25, 2023
@fpistm fpistm added this to In progress in STM32duino libraries via automation Sep 25, 2023
@fpistm fpistm added this to the 0.2.0 milestone Sep 25, 2023
@fpistm fpistm self-requested a review September 25, 2023 13:26
FRASTM and others added 9 commits September 25, 2023 16:14
Include the STM32RTC library to all the BSP as only few functions
remain in the BSP as the RTC is instantiated by the STM32RTC library

The Alarm B of the RTC is used for LoRaWan purpose.
Use the LSE as clock source for the RTC instance.
Set the free running mix mode.

The RTC is configured with the setBinaryModesetRTCMode method before
.begin to set the MIX (BCD + binary) mode.
The RTC irq (for Alarm B) is handled directly by the STM32RTC library
Mask is set to ALL in case of MIX mode, so that interrupt is trigged
on the sub-second basis (other calendar values do not care)
Let the IsEnabled.RtcFeatures be handled by the RTC library

Signed-off-by: Francois Ramu <[email protected]>
Give the parameters a 32-bit value to match the
SubSecond register of the RTC.

Signed-off-by: Francois Ramu <[email protected]>
In Mix mode, the SSR is counting on a fqce APRE which is
RTCCLK freq / 'PREDIV_A + 1).
For example for Nucleo_WL55JC, this value is 256Hz
when RTC is clocked by LSE.
This frqe gives a tick of 3.9ms (= 1/256 * 1000)

Signed-off-by: Francois Ramu <[email protected]>
Signed-off-by: Frederic Pillon <[email protected]>
The timeout is a nb of tick counter (1/256Hz) in mix mode
and must be converted in ms to match the RTC_StartAlarm API
(1 tick is 3.9ms)

Signed-off-by: Francois Ramu <[email protected]>
Modifying the basic.ino to format the Tx packet with the current
calendar Date and Time
Get the RTC instance initialized in MIX mode

Signed-off-by: Francois Ramu <[email protected]>
Configuration is not the same than Arduino IDE.

Signed-off-by: Frederic Pillon <[email protected]>
Signed-off-by: Frederic Pillon <[email protected]>
Signed-off-by: Frederic Pillon <[email protected]>
@fpistm
Copy link
Member

fpistm commented Oct 12, 2023

@fpistm fpistm linked an issue Oct 12, 2023 that may be closed by this pull request
Copy link
Member

@fpistm fpistm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

STM32duino libraries automation moved this from In progress to Reviewer approved Oct 12, 2023
@fpistm fpistm merged commit 44f5e5f into stm32duino:main Oct 12, 2023
2 checks passed
STM32duino libraries automation moved this from Reviewer approved to Done Oct 12, 2023
@fpistm fpistm deleted the millisec_rtc_mix branch October 12, 2023 09:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Development

Successfully merging this pull request may close these issues.

LoRaWAN with low power and RTC
2 participants