blob: 478731247a32f03ee8298d6ad85c5c69f8b4d2c1 [file] [log] [blame]
Daniel Camporacfcf47c2015-06-10 23:29:56 +02001.. _pyb.RTC:
2
Damien Georgea58713a2014-10-31 22:21:37 +00003class RTC -- real time clock
4============================
Damien George88d30542014-10-31 01:37:19 +00005
6The RTC is and independent clock that keeps track of the date
7and time.
8
9Example usage::
10
11 rtc = pyb.RTC()
12 rtc.datetime((2014, 5, 1, 4, 13, 0, 0, 0))
13 print(rtc.datetime())
14
15
16Constructors
17------------
18
19.. class:: pyb.RTC()
20
21 Create an RTC object.
22
23
24Methods
25-------
26
27.. method:: rtc.datetime([datetimetuple])
28
29 Get or set the date and time of the RTC.
30
31 With no arguments, this method returns an 8-tuple with the current
32 date and time. With 1 argument (being an 8-tuple) it sets the date
33 and time.
34
Daniel Camporaea2cc2b2015-06-11 15:53:31 +020035 .. only:: port_pyboard
Damien George88d30542014-10-31 01:37:19 +000036
Daniel Camporaea2cc2b2015-06-11 15:53:31 +020037 The 8-tuple has the following format:
38
39 (year, month, day, weekday, hours, minutes, seconds, subseconds)
40
41 ``weekday`` is 1-7 for Monday through Sunday.
42
43 ``subseconds`` counts down from 255 to 0
44
45 .. only:: port_wipy
Damien George88d30542014-10-31 01:37:19 +000046
Daniel Camporaea2cc2b2015-06-11 15:53:31 +020047 The 8-tuple has the following format:
48
49 ``(year, month, day, weekday, hours, minutes, seconds, milliseconds)``
50
51 ``weekday`` is 0-6 for Monday through Sunday.
Damien George88d30542014-10-31 01:37:19 +000052
Daniel Camporacfcf47c2015-06-10 23:29:56 +020053.. only:: port_pyboard
Damien Georgedea853d2015-04-21 22:35:17 +010054
Daniel Camporacfcf47c2015-06-10 23:29:56 +020055 .. method:: rtc.wakeup(timeout, callback=None)
56
57 Set the RTC wakeup timer to trigger repeatedly at every ``timeout``
58 milliseconds. This trigger can wake the pyboard from both the sleep
59 states: :meth:`pyb.stop` and :meth:`pyb.standby`.
60
61 If ``timeout`` is ``None`` then the wakeup timer is disabled.
62
63 If ``callback`` is given then it is executed at every trigger of the
64 wakeup timer. ``callback`` must take exactly one argument.
65
66 .. method:: rtc.info()
67
68 Get information about the startup time and reset source.
69
70 - The lower 0xffff are the number of milliseconds the RTC took to
71 start up.
72 - Bit 0x10000 is set if a power-on reset occurred.
73 - Bit 0x20000 is set if an external reset occurred
74
75 .. method:: rtc.calibration(cal)
76
77 Get or set RTC calibration.
78
79 With no arguments, ``calibration()`` returns the current calibration
80 value, which is an integer in the range [-511 : 512]. With one
81 argument it sets the RTC calibration.
82
83 The RTC Smooth Calibration mechanism addjusts the RTC clock rate by
84 adding or subtracting the given number of ticks from the 32768 Hz
85 clock over a 32 second period (corresponding to 2^20 clock ticks.)
86 Each tick added will speed up the clock by 1 part in 2^20, or 0.954
87 ppm; likewise the RTC clock it slowed by negative values. The
88 usable calibration range is:
89 (-511 * 0.954) ~= -487.5 ppm up to (512 * 0.954) ~= 488.5 ppm
Damien Georgedea853d2015-04-21 22:35:17 +010090
Daniel Camporacfcf47c2015-06-10 23:29:56 +020091.. only:: port_wipy
Damien Georgedea853d2015-04-21 22:35:17 +010092
Daniel Camporacfcf47c2015-06-10 23:29:56 +020093 .. method:: rtc.callback(\*, value, handler=None, wakes=pyb.Sleep.ACTIVE)
94
95 Create a callback object triggered by a real time clock alarm.
96
97 - ``value`` is the alarm timeout in milliseconds. This parameter is required.
98 - ``handler`` is the function to be called when the callback is triggered.
99 - ``wakes`` specifies the power mode from where this interrupt can wake
100 up the system.
Damien Georgedea853d2015-04-21 22:35:17 +0100101