Garbled output RTC

68gt500

New Member
Hello,

I need some help - again.

Struggling with the Tiny RTC Module.

I got as far as setting the time, and i can actualy read and display it on the Oled. Most of the code I snipped out of the several posts here.

Problem now is that the Time (Hour, Min, Sec) sporadically jump back & forth. Hour does not seem to increase.

Here is some output
16:19:33
16:19:35
16:19:33
16:19:34
16:19:40
16:19:42
16:19:43
16:19:41
16:19:42
16:19:48
16:19:50
16:19:51
16:19:49
16:19:51
16:19:56
16:19:58
16:19:59
16:16:01
16:16:03
16:16:00
16:16:02
16:16:08

Shows the same values on variables (debug screen), sertxd output as on the Oled.

setup:
08m2 on 08 Proto Board.
Tiny RTC module
4,7K Pullup resistors for both SDA SCL
Connectors between the proto board and the RTC are short, max 4" -tried different ones - no change
Stable 4.5V - also tried down to 3.3V - no change
The read in variables seem garbled, coming like that from the rtc module...

Code is from this forum posts here - with minor adaptations for language and format.

Code:
#rem

I2C DS1307 / DS3231 RTC set / test program
Note. the data to/from RTC is in BCD format
2400,8,N,1 OLED / LCD on pin c.4

HIT PROGRAM 20 SEC BEFORE ACTUAL TIME

#endrem

; Funktioniert FAST --- Anzeige Tag, Datum so weit ok,
; Uhrzeit - seltsame Spr?nge 
; Anzeige Interne Spannung --> OK!

#picaxe 08M2
#no_data
;#terminal 4800

symbol baud = N2400
symbol oled = C.4
symbol seconds = b0
symbol mins = b1
symbol hour = b2
symbol day = b3
symbol date = b4
symbol month = b5
symbol year = b6
symbol control = b7
symbol temp = b8

init:
                hi2csetup i2cmaster, %11010000, i2cslow, i2cbyte ;set RTC slave address
                pause 800
                serout oled,baud,(254,1)
                pause 100


;uncomment the line below to update the clock time

;goto set_clock


main:                 ;read time and date, send to display
      do
                
                hi2cin 0,(seconds,mins,hour,day,date,month,year)
                pause 100
                bcdtoascii seconds,b10,b11
                bcdtoascii mins,b12,b13
                bcdtoascii hour,b14,b15
                bcdtoascii date,b16,b17
                bcdtoascii month,b18,b19
                bcdtoascii year,b20,b21
                
                select case day                       ;converts 'day' variable to day of week for display
                 case 1 serout oled,baud,(254,128," Mo ")
                 case 2 serout oled,baud,(254,128," Die")
                 case 3 serout oled,baud,(254,128," Mi ")
                 case 4 serout oled,baud,(254,128," Do ")
                 case 5 serout oled,baud,(254,128," Fr ")
                 case 6 serout oled,baud,(254,128," Sa ")
                 case 7 serout oled,baud,(254,128," So ")
                endselect
                serout oled,baud,(254,133,b16,b17,".",b18,b19,".20",b20,b21) ;positioned for 20X4 or
		    pause 500
                serout oled,baud,(254,193,b14,b15,":",b12,b13,":",b10,b11)   ;16X2 char display
                
                calibadc10 w2
                w2 = 10486/w2
                bintoascii w2,b6,b7,b8
                serout C.4,baud,(254,203,b7,".",b8,"v")
		    Sertxd (b14,b15,":",b12,b13,":",b10,b11, cr,lf)
		    
                pause 800
      loop
                
set_clock:        ;write time and date e.g. 08:52:00 on Sat 01/03/14
                  ;Monday is day 1, Sunday is day 7
                let seconds = $00                                  ;00 secs
                let mins    = $35                                  ;52 mins
                let hour    = $16                                  ;18 hours
                let day     = $01                                  ;02 day of week
                let date    = $16                                  ;16 day
                let month   = $10                                  ;10 month
                let year    = $17                                  ;17 year
                let control = %00010000 ;Enable output at 1Hz

                hi2cout 0,(seconds,mins,hour,day,date,month,year,control)

                goto main

Any ideas what else to try? Different pullups?

Any input appreciated

Mike
 

Technical

Technical Support
Staff member
Pullups are working fine as you are getting some data, even if it is not as expected.

Make sure the watch crystal fitted is the correct type. Many cheap ebay versions of this board come with the wrong and/or broken watch crystal fitted.
 

hippy

Technical Support
Staff member
It does seem odd that the RTC should be jumping all over the place. Perhaps the first thing to do is try some simpler code to see if that demonstrates the same issue -

Code:
#Picaxe 08M2
#Terminal 4800

HI2cSetup I2CMASTER, $D0, I2CSLOW, I2CBYTE
Do
  Do
    HI2cIn 0,( b0, b1, b2 )
  Loop Until b0 <> b3
  b3 = b0
  BcdToAscii b0, b10, b20
  BcdToAscii b1, b11, b21
  BcdToAscii b2, b12, b22
  SerTxd( b12,b22,":",b11,b21,":",b10,b20,CR,LF)
Loop
 

68gt500

New Member
Hello Hippy,

thanks for your suggestion.
I tried the code and get exactly the same results.
16:26:34
16:26:35
16:26:32
16:26:33
16:26:34
16:26:35
16:26:40
16:26:41
16:26:42
16:26:43
16:26:40
16:26:41
16:26:42

Still jumping on the seconds and no hour increase.
Any other thoughts - short of replacing that module?

I read that the DS3231 is an improved -more precise version
 

MartinM57

Moderator
IIRC I bought 3 cheap chinese RTC DS1307 modules a few years ago (the ones with a 3.6v lithium allegedly rechargeable 2032 coin cell). The first one I tried was hopeless (I think it had the same symptoms as yours) and went in the bin. The other two are still in their sealed bags.

I've also had genuine DS1307 that were very temperamental with (genuine) crystals.

(A genuine) DS3231 is more accurate than a (genuine) DS1307 and DS3231 doesn't need an external crystal - I've used about 300 (genuine - Farnell, Mouser etc) DS3231s in the last 3-4 years and never had a problem with one of them. Strictly they are 3v3 devices but are 5v tolerant. I suspect there are Chinese versions of DS3231 which may or may not be as good as a genuine one. More battery-backed RAM in a DS3231 as well...

[EDIT]..some facts corrected in post #15
 
Last edited:

bpowell

Senior Member
I've worked with a handful of RTCs...some pre-built PCBs, some were raw chips I built up...the only time I've received garbage out of them, is when I've loaded a register with a value that is not allowed....e.g. Putting a value larger than 7 into the "Day" field...or larger than 12 in the month field, etc...when you exceed those values, strange things start to happen.

I'd take a look at your clock-set routine, and make sure you're not sending a value to the clock that is outside of its specifications. From what I see, it looks good...but it might be worth *resetting* the clock...as once you load dorked-up info into the clock, it will try to run with it regardless...hence the reason Hippy's "read only" code is showing the same results you were getting.
 

hippy

Technical Support
Staff member
It does look like the Tiny RTC you have may be faulty because jumping back a few seconds doesn't seem to make sense.

I have had a Tiny RTC module I picked up during my car boot sale wanderings lying in a drawer for a while so you inspired me to wire that up and test it. That seems to work as I would expect it to and also proved the test code earlier.

The module has SCL and SDA pull-ups on-board so it might be worth removing the external ones from your circuit. Likewise it might be worth trying without the coin cell battery. You could also try resoldering the crystal wires, even giving the crystal a sharp but not too hard tap.

I think those are all in the 'clutching at straw' category and it may be you unfortunately got a defective module. It might still have some use as an I2C Eeprom module if nothing else.
 

bpowell

Senior Member
I think you're probably under-powering the RTC...

4.5 is the *minimum* voltage for the DS1307 chip...you also said you tried it at 3.3V...that won't work...it will likely be in battery backup mode at that voltage, and won't talk I2C.

Put 5V on it...re-set the time, and see what happens.
 

68gt500

New Member
Thanks for all the input..

I´d like to expand on bpowell´s idea - maybe I did send it some garbage...

I removed the battery and let it sit for an hour.

checked for duplicate pullups - yes there were some, which i removed.

Then I used this to set the time:

Code:
set_clock:        ;write time and date e.g. 08:52:00 on Sat 01/03/14
                  ;Monday is day 1, Sunday is day 7
                let seconds = $01                                  ;00 secs
                let mins    = $45                                  ;52 mins
                let hour    = $20                                  ;18 hours
                let day     = $01                                  ;02 day of week
                let date    = $16                                  ;16 day
                let month   = $10                                  ;10 month
                let year    = $17                                  ;17 year
                let control = %00010000 ;Enable output at 1Hz

                hi2cout 0,(seconds,mins,hour,day,date,month,year,control)
Gabrage even worse, can´t even set the year correctly...

I also tried the RTC setting wizzard:

which returns a failed

Code:
symbol secs     = b0
symbol mins     = b1
symbol hour     = b2
symbol dow      = b3 : symbol chkdow   = b9
symbol day      = b4 : symbol chkday   = b10
symbol month    = b5 : symbol chkmonth = b11
symbol year     = b6 : symbol chkyear  = b12
symbol century  = b7
symbol control  = b8 : symbol chkctrl  = b13

  hi2csetup i2cmaster, %11010000, i2cslow, i2cbyte

  century = $20
  year    = $17
  month   = $10
  day     = $16
  dow     = $02
  hour    = $21
  mins    = $29
  secs    = $31
  control = $10

  hi2cout 0, (secs, mins, hour, dow, day, month, year, control)
  pause 50

  hi2cin 3, (chkdow, chkday, chkmonth, chkyear)
  if chkdow   <> dow     then fail
  if chkday   <> day     then fail
  if chkmonth <> month   then fail
  if chkyear  <> year    then fail

ok:
  sertxd("Time set okay",cr,lf)
  pause 1000
  goto ok

fail:
  sertxd("Time setting failed",cr,lf)
  pause 1000
  goto fail

I think this module is ready for the bin...

Mike
 

68gt500

New Member
Thanks bpowell,

I just tried it with a stable 5.0V - the same garbage.

I just ordered a new 3231 module - I´ll post the results, as soon as it comes in.

The same code applies - doesn´t it?

Mike
 

lbenson

Senior Member
For me (not having tried every possible permutation) code that worked on a DS1307 module works on a DS3231 module.
 

newplumber

Senior Member
Hi
I have the same as MartinM57 mentions in post#5 "cheap chinese RTC DS1307" and its funny mine too are still in the bag sliding closer to the bin/can
as I tried making two of them work...with horrible time keeping...after I bought some ds3231 RTC's I never had a problem.
 

68gt500

New Member
I´ll wait for the 3231 to arrive...

I can think of one application for that tiny RTC - generate random Numbers....:rolleyes:

Mike
 

68gt500

New Member
To finalize this thread:

Yes, you were right - the RTC module was defective.

I hooked up the new DS3231 and with no changes at all, I was able to set it and it inmediately started displaying all Data without a hitch.

Boy, that really did cost me hours of time and I probably lost some hair over it.

On the other side, I think I learned quite a bit.

Thank you all!

Mike
 

newplumber

Senior Member
thats sweet 68gt500 ... hopefully they will be as perfect as the ones i bought...I am still impressed after 2.5 years its right on to the second.
when I first tried the cheap ds1307 ones I was amazed/happy I got it to work ... only took me a few days to realize (since RTC's were new to me) its horribly off time.
 

Goeytex

Senior Member
For the record...

Earlier this year I purchased 3 Tiny RTC modules through Amazon. The idea was to use these to write a DS1307 library. However, on these modules, both the DS1307 and 24C32 chips were identified to be fakes/counterfeits. One module was DOA. On another module the battery holder fell off when I opened the package (but was repairable). Of the two that were eventually made to work, both lost over a minute per hour... I replaced the crystal on one with a crystal I purchased from Rev_Ed and the accuracy improved within 2 seconds per hour. Suffice it to say that these module are junk.

Goey
 

68gt500

New Member
Small Update:
I had the RTC running all Weekend (since it came without the 3V button cell) - alongside a GPS based clock.
By eye I can´t see a difference..
Today the 3V cell came in and now I can power on / off - without loosing the time.

Amazing, what a few &#8364; can buy today...

Now, off to other projects...

Mike
 

The bear

Senior Member
@68gt500,
I've been following your post with great interest, purchased a DS3231(eBay) & using a 08M2 & Oled, however I'm struggling with the connections between the two.
You have the Oled on C.4, Hi2cout on C.0, is that SCL or SDA?
My query is; Which pins do SCL & SDA connect to? I appreciate its probably obvious to someone who understands the program code fully.
I have used the Oled successfully with a temperature display.
Regards, bear..
 

The bear

Senior Member
Thanks, premelec, I saw that.

From the program in question,

"main: ;read time and date, send to display
do
hi2cin 0,(seconds,mins,hour,day,date,month,year)" HI2Cin 0 ??

Still confused.
Regards, bear..
 

inglewoodpete

Senior Member
Thanks, premelec, I saw that.

From the program in question,

"main: ;read time and date, send to display
do
hi2cin 0,(seconds,mins,hour,day,date,month,year)" HI2Cin 0 ??

Still confused.
Regards, bear..
bear, there are 3 commands that you need to become familiar with when programming i2c.

The first is hi2cSetup. Without this command being executed, an i2c read or write is likely to cause the PICAXE chip to 'lock up' if it tried the read or write to the slave chip. The setup command specifies the default slave device's address. Have a read of the command descriptions for a discussion of all parameters and available options.

hi2cIn and hi2cOut allow the master to read and write to memory locations in the slave device.

hi2cin 0,(seconds,mins,hour,day,date,month,year)" HI2Cin 0 ??
hi2cIn 0, (....) is telling the master PICAXE to read the device at the default i2c address (in the example the RTC), starting at the slave's memory location 0 (being the seconds value). Slave location 1 contains the minutes value, 2 has the hours etc.

Once you get your head around PICAXE's implementation i2c, you will find it quite easy to use.:eek:
 

68gt500

New Member
Just for interest, was the new DS3231 an eBay purchase or from a "reputable" supplier?
Whatever "reputable" supplier" might mean... But no, I just chose a relatively cheap one with a high rating and dispatching from Germany (which is local to me).

Banggood&China just takes more time that I have patience for.

Greetings
Mike
 
Top