Daniel Campora | cfcf47c | 2015-06-10 23:29:56 +0200 | [diff] [blame] | 1 | .. _pyb.RTC: |
| 2 | |
Damien George | a58713a | 2014-10-31 22:21:37 +0000 | [diff] [blame] | 3 | class RTC -- real time clock |
| 4 | ============================ |
Damien George | 88d3054 | 2014-10-31 01:37:19 +0000 | [diff] [blame] | 5 | |
| 6 | The RTC is and independent clock that keeps track of the date |
| 7 | and time. |
| 8 | |
| 9 | Example usage:: |
| 10 | |
| 11 | rtc = pyb.RTC() |
| 12 | rtc.datetime((2014, 5, 1, 4, 13, 0, 0, 0)) |
| 13 | print(rtc.datetime()) |
| 14 | |
| 15 | |
| 16 | Constructors |
| 17 | ------------ |
| 18 | |
| 19 | .. class:: pyb.RTC() |
| 20 | |
| 21 | Create an RTC object. |
| 22 | |
| 23 | |
| 24 | Methods |
| 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 Campora | ea2cc2b | 2015-06-11 15:53:31 +0200 | [diff] [blame^] | 35 | .. only:: port_pyboard |
Damien George | 88d3054 | 2014-10-31 01:37:19 +0000 | [diff] [blame] | 36 | |
Daniel Campora | ea2cc2b | 2015-06-11 15:53:31 +0200 | [diff] [blame^] | 37 | 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 George | 88d3054 | 2014-10-31 01:37:19 +0000 | [diff] [blame] | 46 | |
Daniel Campora | ea2cc2b | 2015-06-11 15:53:31 +0200 | [diff] [blame^] | 47 | 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 George | 88d3054 | 2014-10-31 01:37:19 +0000 | [diff] [blame] | 52 | |
Daniel Campora | cfcf47c | 2015-06-10 23:29:56 +0200 | [diff] [blame] | 53 | .. only:: port_pyboard |
Damien George | dea853d | 2015-04-21 22:35:17 +0100 | [diff] [blame] | 54 | |
Daniel Campora | cfcf47c | 2015-06-10 23:29:56 +0200 | [diff] [blame] | 55 | .. 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 George | dea853d | 2015-04-21 22:35:17 +0100 | [diff] [blame] | 90 | |
Daniel Campora | cfcf47c | 2015-06-10 23:29:56 +0200 | [diff] [blame] | 91 | .. only:: port_wipy |
Damien George | dea853d | 2015-04-21 22:35:17 +0100 | [diff] [blame] | 92 | |
Daniel Campora | cfcf47c | 2015-06-10 23:29:56 +0200 | [diff] [blame] | 93 | .. 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 George | dea853d | 2015-04-21 22:35:17 +0100 | [diff] [blame] | 101 | |