2222"""
2323`adafruit_ds3231` - DS3231 Real Time Clock module
2424=================================================
25- MicroPython library to support DS3231 Real Time Clock (RTC).
25+ CircuitPython library to support DS3231 Real Time Clock (RTC).
2626
27- This library supports the use of the DS3231-based RTC in MicroPython .
27+ This library supports the use of the DS3231-based RTC in CircuitPython .
2828
2929Author(s): Philip R. Moyer and Radomir Dopieralski for Adafruit Industries.
30- Date: November 2016
31- Affiliation: Adafruit Industries
3230
3331Implementation Notes
3432--------------------
3533
3634**Hardware:**
3735
38- * Adafruit `Feather HUZZAH ESP8266 <https://www.adafruit.com/products/2821>`_ (Product ID: 2821)
39- * Adafruit `Feather M0 Adalogger <https://www.adafruit.com/products/2796>`_ (Product ID: 2796)
40- * Adafruit `Arduino Zero <https://www.adafruit.com/products/2843>`_ (Product ID: 2843)
36+ * Adafruit `DS3231 Precision RTC FeatherWing <https://www.adafruit.com/products/3028>`_ (Product ID: 3028)
4137* Adafruit `DS3231 RTC breakout <https://www.adafruit.com/products/3013>`_ (Product ID: 3013)
38+ * Adafruit `ChronoDot - Ultra-precise Real Time Clock - v2.1 <https://www.adafruit.com/products/255>`_ (Product ID: 3013)
4239
4340**Software and Dependencies:**
4441
45- * Adafruit's MicroPython firmware for the ESP8622 and M0-based boards: https://github.com/adafruit/micropython/releases
46- * Adafruit's register library: https://github.com/adafruit/Adafruit_MicroPython_Register
42+ * Adafruit CircuitPython firmware for the ESP8622 and M0-based boards: https://github.com/adafruit/micropython/releases
43+ * Adafruit's Register library: https://github.com/adafruit/Adafruit_CircuitPython_Register
44+ * Adafruit's Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
4745
4846**Notes:**
4947
@@ -67,7 +65,9 @@ class DS3231:
6765 datetime_register = i2c_bcd_datetime .BCDDateTimeRegister (0x00 )
6866 """Current date and time."""
6967
70- alarm1 = i2c_bcd_datetime .BCDAlarmTimeRegister (0x07 )
68+ # The first alarm supports seconds but we ignore it by starting at 0x8
69+ # instead of 0x7.
70+ alarm1 = i2c_bcd_datetime .BCDAlarmTimeRegister (0x08 )
7171 """Alarm time for the first alarm."""
7272
7373 alarm1_interrupt = i2c_bit .RWBit (0x0e , 0 )
@@ -85,8 +85,19 @@ class DS3231:
8585 alarm2_status = i2c_bit .RWBit (0x0f , 1 )
8686 """True if alarm2 is alarming. Set to False to reset."""
8787
88- def __init__ (self , i2c , device_address = 0x68 ):
89- self .i2c_device = I2CDevice (i2c , device_address )
88+ def __init__ (self , i2c ):
89+ self .i2c_device = I2CDevice (i2c , 0x68 )
90+
91+ # Try and verify this is the RTC we expect by checking the rate select
92+ # control bits which are 1 on reset and shouldn't ever be changed.
93+ buf = bytearray (2 )
94+ buf [0 ] = 0x0e
95+ with self .i2c_device as i2c :
96+ i2c .writeto (buf , end = 1 , stop = False )
97+ i2c .readfrom_into (buf , start = 1 )
98+
99+ if (buf [1 ] & 0b00011000 ) != 0b00011000 :
100+ raise ValueError ("Unable to find DS3231 at i2c address 0x68." )
90101
91102 @property
92103 def datetime (self ):
0 commit comments