Thanks to visit codestin.com
Credit goes to github.com

Skip to content

mimxrt: Provide the machine.RTC module. #7318

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

Closed
wants to merge 3 commits into from

Conversation

robert-hh
Copy link
Contributor

@robert-hh robert-hh commented May 25, 2021

Initial version, using the LP rtc clock.
It provides setting the Date & Time with rtc.init() or rtc.datetime()
and reading date & time with rtc.datetime() or rtc.now().

If no battery is supplied, the default boot time/date is 1970/1/1 0:0:0.
With a battery, the clock continues to run even when the board is not
powered. The clock is quite precise. If not, using rtc.calibration()
may help.

Possible extension: set an alarm with alarm handler. For short periods
< 70 minutes this is also possible with the timer module,
for longer periods this may have to be done.

@robert-hh robert-hh force-pushed the mimxrt_rtc branch 2 times, most recently from 65c1733 to 327bf65 Compare May 25, 2021 16:17
@robert-hh robert-hh changed the title mimxrt: Provide a RTC module. mimxrt: Provide the machine.RTC module. May 25, 2021
@dpgeorge
Copy link
Member

Thanks for this. But we really need to first standardise on a format for the RTC tuple. It should really match CPython's datetime.datetime. What do you implement here?

@robert-hh
Copy link
Contributor Author

I used the format documented under machine.RTC(). So it's (year, month, day, weekday, hour, minute, second, fraction). I can change that anytime, if there is a standard.

@robert-hh
Copy link
Contributor Author

I just looked at the Python datetime.datetime() format. That 's obviously easy. The built-in RTC does not support weekday, and I only implemented that for consistency with the MP docs. tzinfo could be None in the first step. But RTC could still be useful in combination with the file system, especially since MIMXRT MCU's support battery backup for the RTC (and it works).

robert-hh added 3 commits June 1, 2021 18:23
Initial version, using the LP rtc clock.
It provides setting the Date & Time with rtc.init() or rtc.datetime()
and reading date & time with rtc.datetime() or rtc.now().

If not battery is supplied, the default boot time/date is 1970/1/1 0:0:0.
With a battery, the clock continues to run even when the board is not
powered. The clock is quite precise. If not, using rtc.calibration()
may help.

Possible extension: set an alarm with alarm handler. For short periods
< 70 minutes this is also possible with the timer module,
for longer periods this may have to be done.
The tuple order for datetime was changed to the CPython sequence:
Year, Month, Day, Hour, Minute, Second, µsecond, TZ
TZ is ignored and reported as None.
µsecond is used at best effort.

The method weekday() was added to report the weekday of the current
date. It starts with 0 for Monday.
@dpgeorge
Copy link
Member

dpgeorge commented Jun 3, 2021

Merged in 2f365d2 with a fix for setting the datetime, to use the new tuple ordering/format.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants