Digistump Forums

The Digispark => Digispark Libraries => Topic started by: ngoline on February 27, 2013, 10:31:26 am

Title: DS1307 RTC library
Post by: ngoline on February 27, 2013, 10:31:26 am
Hi, I've looked everywhere but couldn't find a library to work with a Real Time Clock on Digispark, so I've decided to modify what I found and make it work my way.


I put out this project on GitHub (http://github.com/nGoline/TinyRTClib) (http://github.com/nGoline/TinyRTClib).

It's based on Adafruit's project also on GitHub (http://github.com/adafruit/RTClib).
I've changed it to point to TinyWireM instead of Wire and made some modifications to the methods that call Wire 'cause in the TinyWireM library they have different methods like Wire.write() is actually TinyWireM.send()...

In the examples we have 3 codes. The softrtc is meant to run by the first time you put the batteries on, from that point you'll have as long as 9 years of correct Date and Time.

Enjoy!

Níckolas Goline
Title: Re: DS1307 RTC library
Post by: SmeeAgain on February 27, 2013, 01:59:45 pm
Nice job! Are you using pull-ups on the I2C lines? So far I've only used the 1307 on the Arduino and there it works fine without additional pull-ups.
Title: Re: DS1307 RTC library
Post by: Mark on February 27, 2013, 04:45:09 pm
Folks
I2C needs pullups because the devices are open collector or Tri State.

Stick them in as a matter of design practice.

You only need one set either at the master, or in some designs at the device.


Mark
Title: Re: DS1307 RTC library
Post by: ngoline on February 28, 2013, 09:18:16 am
I'm using them with the "Digispark LCD Shield" and the shield already have the pull ups.
I've also made some modifications to the library and will post it latter today.
Title: Re: DS1307 RTC library
Post by: digistump on March 20, 2013, 07:00:08 pm
This is now also included in the official release. http://digistump.com/wiki/digispark/tutorials/connecting#software
Title: Re: DS1307 RTC library
Post by: BStrauss3 on April 14, 2013, 07:51:00 pm
It's been suggested in something I read that we should mask the Hours register because there are some chips that return the value of the 12/24 bit setting register, i.e. make the line in now():
 
uint8_t hh = bcd2bin(TinyWireM.receive() & 0x3F);