Notes on the DS1307/AT24C32 RTC module

Experimenting recently with one of the little (approx. 1"/26mm sq.) DS1307 Real Time Clock (RTC) boards with EEPROM (AT24C32, 4096 bytes), I needed a bit more detail as the majority of sellers on a well known auction site don't seem to offer much if any detail. Even where there is more detail, some descriptions are erroneous, describing the EEPROM for instance as 8192 bytes.

It didn't take long to discover a circuit diagram on an electronics hobby website but even that wasn't 100% accurate, so I hoped it might be useful to other PicAxe users if I posted what I've discovered here. I've since discovered another circuit diagram in other posts on this forum, which also doesn't appear to be wholly accurate.

Being a bit impulsive, I'd already tried installing a standard CR2032 coin cell in the battery holder on the back of the board, to see if the RTC continued to run properly when I turned the power off. It didn't work and, I discovered, the battery was getting warm. I then discovered that there was a bent tab in the battery holder which was shorting the battery (see the battery holder photo). Once unbent, things looked better, but the battery voltage then rose well above the nominal 3.2V it was supposed to be. Time I found the circuit diagram.

Once I'd discovered a circuit diagram, all became clear - the circuit is designed for a rechargeable 3.6V (LiR2032) and to use it with a standard CR2032 cell requires some modifications. The diagram I found suggested removing R4, R5, R6 & D1, replacing R6 with 0 ohms i.e. a bit of wire. I didn't see any point in removing R5 as it's in series with D1, so once that's out R5 doesn't connect to anything. R6 also can be bypassed with a bit of wire without the need to remove it. This then connects the CR2032 directly to the DS1307. R4 must be removed though, otherwise it just drains the battery.

D1 must be removed to avoid trying to charge a battery which isn't designed to be charged - potentially it could catch fire or even explode, though mine didn't even when left for several hours before I realised what was happening. I wouldn't recommend it though!

The attached picture of the component side shows R4 & D1 removed and the R6 bypass link. Before & after circuit diagrams are also attached. The component values are correct according to what I can see from photos on the well known auction site and my own board (not sure about C1 & C2 but it's more likely that they are 100nF rather than 100pF).

Something else I gleaned from the original circuit diagram was that the unoccupied U3 location is designed for the ubiquitous DS18B20 digital thermometer, for which of course PicAxes have a built-in read command (READTEMP/READTEMP12). However the original circuit diagram suggested the board didn't have the required pullup resistor. Wrong, it does, it's R1 but it's 3k3 instead of the recommended 4k7.

The I²C* pullups are also 3k3 instead of 4k7, but the I²C bus seems to work perfectly well as does the DS18B20 I fitted (but it might not if 4k7 pullups were also fitted on the PicAxe board). Note also that the SQ output from the DS1307 has a 3k3 pullup fitted as well which might well be a suitable current source for an LED to show seconds (this output can also be directly controlled via register bits).

The photo with the battery in place shows the position (top right) for the DS18B20 which is fitted on this side as the device outline shows.

At about 41p (at 5x) for this useful board, a 48p DS18B20 (10x) and a 20p CR2032 (5x) battery together with a PicAxe 08M2+, you've got the basis for a remarkably cheap, and tiny, data logger which can store, for instance, four 1-byte values once a day for more than three years and nine months.


* - Pedant mode, it's I²C (for IIC or Inter-Integrated Circuit bus), not 12C (as on the board) nor I2C (though I accept that not all systems can reproduce the ² character).

Note to moderators - if a different forum is more appropriate, please feel free to move this post.
combo.jpg
DS1307-Modules-combo.jpg
 

PhilHornby

Senior Member
Once I'd discovered a circuit diagram, all became clear - the circuit is designed for a rechargeable 3.6V (LiR2032) and to use it with a standard CR2032 cell requires some modifications.
I think I've been here and have a T-shirt somewhere to prove it ;)

The thing is, the DS1307 datasheet says :-
A lithium battery with 48mAhr or greater will back up the DS1307 for more than 10 years in the absence of power at +25°C. UL
So how did someone come to the conclusion it needed a rechargeable battery :confused:
 

lbenson

Senior Member
Note that the DS1307 has frequently been dinged for inaccuracy. The DS3231 on a similar module is considered superior.

Many of the ones I've seen lack the holes for the DS18B20.
 

inglewoodpete

Senior Member
Note that the DS1307 has frequently been dinged for inaccuracy. The DS3231 on a similar module is considered superior.
...which make a mockery of the 10-year backup power. Who needs inaccurate time? I found one DS1307 that slipped up to an hour over a year.
 

PhilHornby

Senior Member
I found one DS1307 that slipped up to an hour over a year.
That's not as bad as the error I see in the one and only DS1307 I have deployed - it loses 17 seconds a day. However, it is extremely consistent, so the software adds 17 seconds @ 04:00am. The clock has to be manually corrected twice a year for Daylight Saving (not a Western Australian phenomenon!) and now it's not usually adrift by more than a few tens of seconds after 6 months. (Perfectly acceptable for a Hot Water timer)

I'm guessing it's probably down to a low quality crystal, or poor layout of the eBay module, rather than the DS1307 itself.
 

newplumber

Senior Member
@ Philhornby lol ...funny I tried the same thing ( recorrect the off time) but my code was off too...so I calmly took all my DS1307's
and tested them to see if they are bullet proof...and was happy they weren't...of course after the fact i found out how awesome the
DS3231 RTC is
 
Note that the DS1307 has frequently been dinged for inaccuracy. The DS3231 on a similar module is considered superior.
Looking at the datasheet for the DS3231 I can see why it's so much better, although it still only has a 32kHz crystal (built in), it has temperature compensation and even crystal ageing compensation. Very impressive. I see also that the temperature data is available so a separate DS18B20 is unnecessary.

Although it's typically £1 (even with a 24C32) for a similar module, the total price for memory, timekeeping and thermometer functions is much the same for a DS3231 board so I shall certainly look at one of those next time I need these functions.
 

MartinM57

Moderator
...just be aware that Chinese modules containing higher end ICs (such as DS1307, DS3231/2 etc) can contain fake/counterfeit ICs which either work perfectly, work partially (poor timekeeping, poor interfacing, not across the specified temperature range etc) or don't work at all.
 

newplumber

Senior Member
Yes true MartinM57 (on be aware of false modules) ...and for some unexplainable reason ...I managed to buy alot of the good DS3231s ...usually my luck is the opposite


@ Hairy Animal ...
it has temperature compensation and even crystal ageing compensation. Very impressive
I didn't know that...but when reading the temp using MARKS code from the DS3231 it seems to be always showing
2.5 F degrees higher ... in my tests ... but I agree with you ..i am always impressed at the time accuracy
 

Jeremy Harris

Senior Member
I bought a few of those exact same modules from a well known auction site, even down to the same logo, tiny. They are, to put it politely, complete garbage. Their timekeeping is appalling, often gaining or losing minutes a day in some cases. I ended up binning them all and in the one project I'd already built with one in, I made my own small DS1307 PCB as a replacement and that works fine, and keeps time very well.

I'm pretty sure they are using fake components, hence all the reports about the poor timekeeping. The genuine DS1307, fitted with a decent crystal, is as good as any other RTC in my experience.
 

mikeyBoo

Senior Member
When considering an RTC plus EEPROM plus temp sensor, depending upon how much added memory is required, a DS3232 with 236 bytes of battery backed RAM and inbuilt temp sensor can also be a viable solution.

Also the clock RAM can be used to get/set IO image registers, LCD display data, etc. to/from the Picaxe using a PC/Pi/etc. if you don’t mind doing a little I2C bus arbitration. (i.e. a BA (bus available) BR (bus request) signals to/from the Picaxe & a (e.g.) 4066 to handoff the bus).

My experience has been about 2 out of 10 ebay DS1307s & some xtals bad. I had to put a pretty wide ground plane around the 1307 to avoid quirkiness (never bothered to investigate why). This was for outdoor usage in same enclosure as a PWM drive.
 

lbenson

Senior Member
While the DS1307 may be capable of accuracy as great as that of the DS3231 (with proper components and design), as noted, the DS3231 (if authentic) provides built-in appropriate crystal and temperature compensation, and prevents some forms of layout mishap. A safer bet for most, I would guess.
 

inglewoodpete

Senior Member
There is another way

Having recently worked with a cheap GPS receiver and background serial reception on a 28X2, I would recommend this as a solution for places where you can get a satellite signal. The modules typically require 3.3v to run but the output data is rock-solid when read into the hSerIn pin of the 28X2 running with 5 volts.

You need no code for uploading or correcting the time. It just locks in the time and, compared to the NTP-synched clock on this computer, is well within a second of the local version of network time. Just add a PCB jumper link to shift the time by an hour if your region endures daylight saving time (what's that? :):))
 

Jeremy Harris

Senior Member
Having recently worked with a cheap GPS receiver and background serial reception on a 28X2, I would recommend this as a solution for places where you can get a satellite signal. The modules typically require 3.3v to run but the output data is rock-solid when read into the hSerIn pin of the 28X2 running with 5 volts.

You need no code for uploading or correcting the time. It just locks in the time and, compared to the NTP-synched clock on this computer, is well within a second of the local version of network time. Just add a PCB jumper link to shift the time by an hour if your region endures daylight saving time (what's that? :):))
I've done this for our house data logging system as the master clock. It works well, and you don't need a link for adjusting for daylight saving time, you just need to know the algorithm used to set the day that the change overs happen.

In the UK, the change from GMT to BST happens at 01:00 GMT on the last Sunday of March and the switch back to GMT happens at 01:00 GMT on the last Sunday of October. Just checking these dates and times makes it easy for the clock to automatically change over at the set times. In my application I log all data using GMT (it's easier that way) but send either GMT or BST to the time display in the hall, just for convenience. It's handy having a very accurate date and time display that also shows data like the outside air temperature, humidity etc.
 

PhilHornby

Senior Member
Or maybe a combination...

Having recently worked with a cheap GPS receiver and background serial reception on a 28X2, I would recommend this as a solution for places where you can get a satellite signal.
But how about applications that need an accurate time signal at all times?

At power-up there will definitely be no valid time data 'for a while' and you could suffer a loss-of-signal during normal operations. This might not matter for a Hot Water controller, but if you accidentally open that Chicken Coop at the wrong time...:p

A hybrid, battery-backed DS3231 set by an external source would seem like an ideal compromise.
 

inglewoodpete

Senior Member
But how about applications that need an accurate time signal at all times?

At power-up there will definitely be no valid time data 'for a while' and you could suffer a loss-of-signal during normal operations. This might not matter for a Hot Water controller, but if you accidentally open that Chicken Coop at the wrong time...:p

A hybrid, battery-backed DS3231 set by an external source would seem like an ideal compromise.
My application fits neatly in between what I described in my earlier post and what Phil describes.

My 'working' clock is software based and uses the 28X2's internal timer interrupting every second, counting the seconds and incrementing minutes and hours when due. The application (A Westminster 'chiming' Clock) accesses the seconds, minutes and hours variables to control the striking of the 'bells'. The GPS module's output is used to continuously synchronise the 28X2's software clock. My experience to date has shown that the GPS data stream occasionally misses a data packet for one or two seconds but not for extended periods.

The clock, called Little Ben has been purchased by the City of Joondalup in Western Australia and we expect to install it a public park in the coming weeks.
 
Last edited:

inglewoodpete

Senior Member
Sounds interesting. Will you be posting details in the projects forum?
I hope to document the project in "Completed Projects" in the coming months. Some forum members may recall that Little Ben was shown in an biennial exhibition called "Sculpture at Bather's Beach" in Fremantle, West.Aust in early 2017. I posted a snippet about that (temporary) exhibition here. The controller is being revamped for a permanent installation, hence the need for ongoing accurate timekeeping.

My apologies - I seem to have hijacked your thread.
 
Top