Mbed with the DS3231 RTC

I have a great little RTC from Love Electronics, it uses the DS3231 chip which is similar to the DS1307 (as shown in this article http://www.l8ter.com/?p=417)

image 

Since I am starting out using mbed (https://mbed.org) it is probably a good example to see if the DS3231 works with the LPC1768.  I started by using the DS1307 library as a guide, but then noticed that there are a few differences. (Note there is an mbed DS3231 library you can import)

image

If you have a look at the datasheets there are a few changes between the models, mainly the DS3231 has 2 alarms and is more accurate.

DS3231 http://datasheets.maximintegrated.com/en/ds/DS3231.pdf

DS1307 https://www.sparkfun.com/datasheets/Components/DS1307.pdf

DS1307

image

DS3231

image

Differences between the DS1307 and the DS1307:

1) Address 00h , BIT 7 , should be 0 not CH (Start stop feature does not exist on DS3231)

2) Address 02h for some reason the mask (on the example driver) was set to 196 but in reality you would want to ignore BIT 7 and BIT 6, use 0xC0 not 196. (Bug?)

3) Address 05h BIT 7 is flipped every time there is an overflow on the years register (06h), so you need to ignore this bit when reading the month.

 

Seconds..

When reading address 00g to get the seconds for some reason they are in the range 0 to 599 and loop every minute. This makes sense but it is not what the datasheet states – Range 00-59.

Leave a Reply

Your email address will not be published. Required fields are marked *