pyb.RTC.rst 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. .. currentmodule:: pyb
  2. .. _pyb.RTC:
  3. class RTC -- real time clock
  4. ============================
  5. The RTC is and independent clock that keeps track of the date
  6. and time.
  7. Example usage::
  8. rtc = pyb.RTC()
  9. rtc.datetime((2014, 5, 1, 4, 13, 0, 0, 0))
  10. print(rtc.datetime())
  11. Constructors
  12. ------------
  13. .. class:: pyb.RTC()
  14. Create an RTC object.
  15. Methods
  16. -------
  17. .. method:: RTC.datetime([datetimetuple])
  18. Get or set the date and time of the RTC.
  19. With no arguments, this method returns an 8-tuple with the current
  20. date and time. With 1 argument (being an 8-tuple) it sets the date
  21. and time (and ``subseconds`` is reset to 255).
  22. The 8-tuple has the following format:
  23. (year, month, day, weekday, hours, minutes, seconds, subseconds)
  24. ``weekday`` is 1-7 for Monday through Sunday.
  25. ``subseconds`` counts down from 255 to 0
  26. .. method:: RTC.wakeup(timeout, callback=None)
  27. Set the RTC wakeup timer to trigger repeatedly at every ``timeout``
  28. milliseconds. This trigger can wake the pyboard from both the sleep
  29. states: :meth:`pyb.stop` and :meth:`pyb.standby`.
  30. If ``timeout`` is ``None`` then the wakeup timer is disabled.
  31. If ``callback`` is given then it is executed at every trigger of the
  32. wakeup timer. ``callback`` must take exactly one argument.
  33. .. method:: RTC.info()
  34. Get information about the startup time and reset source.
  35. - The lower 0xffff are the number of milliseconds the RTC took to
  36. start up.
  37. - Bit 0x10000 is set if a power-on reset occurred.
  38. - Bit 0x20000 is set if an external reset occurred
  39. .. method:: RTC.calibration(cal)
  40. Get or set RTC calibration.
  41. With no arguments, ``calibration()`` returns the current calibration
  42. value, which is an integer in the range [-511 : 512]. With one
  43. argument it sets the RTC calibration.
  44. The RTC Smooth Calibration mechanism adjusts the RTC clock rate by
  45. adding or subtracting the given number of ticks from the 32768 Hz
  46. clock over a 32 second period (corresponding to 2^20 clock ticks.)
  47. Each tick added will speed up the clock by 1 part in 2^20, or 0.954
  48. ppm; likewise the RTC clock it slowed by negative values. The
  49. usable calibration range is:
  50. (-511 * 0.954) ~= -487.5 ppm up to (512 * 0.954) ~= 488.5 ppm