One of the many things I bought a while back was a small PCB containing a DS1307 RTC (http://goo.gl/rfdL78) along with an EEPROM IC (not interfaced in this post…). The DS1307 as far as I know is the universal standard for RTCs offering BCD storage of time and date, along with some user accessible space. Now obviously, the STM32F0 has built in RTC section but on smaller chips like the STM32F050P6 that I used for the Watch 2, there is no option for an external 32.768kHz crystal and you can either choose between a divided version of the external crystal (8MHz) or the poor tolerance internal oscillator. In this instance, using an external chip like this can reduce power requirements and increase time keeping accuracy. The 1 second output could also be used to clock the wakeup input of the MCU allowing the MCU to wakeup and update the time on an LCD, further reducing power consumption.
The power consumption is really small on these chips with the datasheet claiming 500nA when running in battery backup mode. The PCB that I’ve used can also be obtained really cheap from the good ol’ eBay (£0.99! http://goo.gl/Iwpya7 – Link will expire!).
To test the RAM reading and writing functions, a piece of test data was used, as seen above, it was good ol’ 123! As this is stored in RAM, this will be there until power is removed, probably for a long time as I never remove the battery! The time set function is commented out as I’d already set the time. With my code, I use the macros __TIME__ and __DATE__ which are preprocessor commands to fill an array with a time and date string at compilation time. This saves me having to change the time and date every time I run the program and generally only has a few seconds of error which I can tolerate as I never really use that as the final time. With regards to __DATE__, the actual month is presented as a text string so I’ve hardcoded this number in. If the month changes, this will need to be changed by hand!
886uA isn’t half bad! I’m only using the STM32F0 Internal pullups for the I2C bus which isn’t as ideal as using dedicated external 4.7k resistors. Fortuantely, this doesn’t actually cause any data errors and the bus works fine. Realistically, one should add 4.7k resistors pulling the bus up to V+!
The program wasn’t actually too hard to write as I generally copy my compass I2C functions as I don’t like writing the I2C stuff from scratch but nonetheless, you can still find it on my Github!