Tags:
create new tag
view all tags

The Driver for the PCF8563 Real-time Clock and Calendar

This is a pure MicroPython driver written by Lewis He, which can be found on https://github.com/lewisxhe/PCF8563_PythonLibrary

It is implemented as class PCF8563 with the following methods:

  • PCF8563(i2c:!I2C,address=None): Creates an PCF8563 instance. In the first parameter the I2C object from the machine module must be passed. address can be left undefined in which case the default PCF8563 I2C slave address (0x51) is used
  • seconds(): returns seconds of current time
  • minutes(): returns minutes
  • hours() returns hours
  • day(): returns day of the week
  • date(): returns day in the month
  • month(): returns months
  • year(): returns year
  • datetime(): returns the tuple: (year,month,date,hours,minutes,seconds,day)
  • write_all(year=None,month=None,date=None,hours=None,minutes=None,seconds=None,day=None): writes the corresponding value to the pcf8563 registers if not None)
  • set_datetime(dt): dt is a tuple (year, month,date,hours,minutes,seconds,day)
  • write_now(): write utime.localtime() to the PCF8563 registers
  • set_clk_out_frequency(frequency=CLOCK_CLK_OUT_FREQ_1_HZ): sets the clock out pin frequency (1 Hz if frequency is not specified)
  • check_for alarm_interrupt() check i the alarm interrupt is set
  • enable_alarm_interrupt(): enable the alarm interrupt
  • disable_alarm_interrupt(): disable the alarm interrupt
  • set_daily_alarm(hours=None, minutes=None, date=None,weekday=None)
I had some difficulties with the sequence of parameters of datetime(), set_datetime() and write_all() because it did not reflect the sequence returned by utime.localtime, which is
(year,month,date,hours,minutes,seconds,day_of_week). I therefore modified the driver and changed the parameters of these methods.

Then I wrote 2 example programs:

  • rtc_set_time: Sets the time to the current CET time (you can easily modify this to set e.g. GMT time instead)
  • rtc_get_time: Gets date and time from the PCF8563
You can find the code on the github repository: https://github.com/uraich/twatch2020_firmware/tree/main/hardware/pcf8563

-- Uli Raich - 2021-01-25

Comments

Edit | Attach | Watch | Print version | History: r4 < r3 < r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r4 - 2021-01-27 - UliRaich
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback