Serial Clock Module Frustrations

IceQubed

Member
Hi, I'm trying to get the clock module that can be integrated into the serial OLED module working. I can output text to the OLED display perfectly well, however when I try to set the time (and display it on the OLED) it just displays "00/00/00 00:00". I am using the 20M2 chip, and am connected in a serial connection the the OLED firmware/clock board through the default pins (B.7 is output, B.0 is input). The DS1307 clock module and battery are inserted correctly.

Here is the code copied directly from the manual:
Code:
init: pause 500
main: serout B.7,N2400, (253,0,"25/12/01 22:00  ")
pause 1000
serout B.7,N2400, (0)
end
I have also attempted:
Code:
init: pause 1000
setfreq m16
main: 
serout B.7,N2400_16, (253,0,"25/12/01 22:00  ")
pause 4000
serout B.7,N2400_16, (0)
end
Neither of these work, they both give me "00/00/00 00:00". I have noticed that occasionally after programming it will turn to "3F/00/00 00:00", which I assume is just random data or some glitch? I do get the "** DATA 0 SET **" text appearing when I program it, which is a good sign.

Any ideas on how to fix the clock? I'm thinking it could be some data speed issues or something.
 

westaust55

Moderator
I have not experimented with the DS1307 in recent times but recall it sometime took a while (up to around 30 seconds) for an update of the time to be displayed.

try this code:
Code:
init: 
    pause 500
main: 
    serout B.7,N2400, (253,0,"25/12/01 22:00  ")
again:
    pause 1000
    serout B.7,N2400, (0)
    goto again
 

IceQubed

Member
I have not experimented with the DS1307 in recent times but recall it sometime took a while (up to around 30 seconds) for an update of the time to be displayed.

try this code:
Code:
init: 
    pause 500
main: 
    serout B.7,N2400, (253,0,"25/12/01 22:00  ")
again:
    pause 1000
    serout B.7,N2400, (0)
    goto again
Sadly this doesn't seem to fix the issue, it is still "00/00/00 00:00" even after waiting for a few minutes with the program working. After a while, it changes to "3F/00/00 00:00"
 

Technical

Technical Support
Staff member
It sounds like your DS1307 is not working/powered correctly - how have you powered the AXE033Y whole board?
 

IceQubed

Member
I have the datasheet, that's what I'm using for code reference etc. I'm using this serial oled module with the optional clock module & battery installed on its firmware board.

I'm powering it from a 6v mains adapter through a 5v voltage regulator. This regulated voltage is shared by the 20M2, and has plenty of current for both.
 

Technical

Technical Support
Staff member
What type of regulator - many common 5V regulators will *not* work correctly at 6V.
 

IceQubed

Member
Aha thank you, your reply made me recheck my power supply, it is actually 5V! I removed the voltage regulator (78L05) and it worked!
 

Kecked

Member
I just went through this and here is what I learned. Use the code shown in the manual to set the clock. Here is the code I use and it works. Just unrem the set clock section. Also you need to put the mode jumper on so it is in i2c mode. Once you set the clock if you just want a clock remove the mode jumper and short the clock jumper. You can not both use the rtc bus and the serial at the same time. IF you want to use the display in serial mode use a separte ds1307 and crystal and make a separate i2c bus just for the clock function.

Code:
#picaxe 28x2


'ANALOG CLOCK WITH LCD September 23, 2012
'Marc Rubin

'Set Clock

let dirsB = %11111111
let adcsetup = 0
setfreq m4
Pause 250

	Symbol seconds 	= b0
	Symbol mins 	= b1
	Symbol hour 	= b2
	Symbol day 		= b3
	Symbol date 	= b4
	Symbol month 	= b5
	Symbol year 	= b6
	Symbol control 	= b7
#rem
      Let day     	= $01
	Let year    	= $12	
	Let month   	= $09	
	Let date    	= $30	
	Let hour    	= $21	
	Let mins    	= $02	
	Let seconds 	= $30	
 	Let control 	= %00010000 ; Enable output at 1Hz


'Write to Clock on I2C Bus

  hi2csetup i2cmaster, %11010000, i2cslow_32,i2cbyte
  writei2c 0, (seconds, mins, hour, day, date, month, year, control)
#endrem


Main:

'Readout Clock on I2C Bus

		i2cslave %11010000, i2cslow_8, i2cbyte
		readi2c 0, (seconds, mins, hour, day, date, month, year, control)
	


'BCD to ASCII Conversion

			BCDTOASCII hour,		b8,b9
 			BCDTOASCII mins,		b10,b11
 			BCDTOASCII seconds,	b12,b13
 			BCDTOASCII month, 	b14,b15
 			BCDTOASCII date, 		b16,b17
 			BCDTOASCII year, 		b18,b19

'Determine day of week

	IF DAY=1 THEN LET B20="S":LET B21="U":LET B22="N"
	ENDIF
 	IF DAY=2 THEN LET B20="M":LET B21="O":LET B22="N"
	ENDIF
	IF DAY=3 THEN LET B20="T":LET B21="U":LET B22="E"
	ENDIF
	IF DAY=4 THEN LET B20="W":LET B21="E":LET B22="N"
	ENDIF
	IF DAY=5 THEN LET B20="T":LET B21="H":LET B22="U"
	ENDIF
	IF DAY=6 THEN LET B20="F":LET B21="R":LET B22="I"
	ENDIF
	IF DAY=7 THEN LET B20="S":LET B21="A":LET B22="T"
	ENDIF

'Send to LCD
			i2cslave $C6,i2cslow_8,i2cbyte
			pause 10
			hi2cout 0,($FE,$80,$20,$20,$20,$20,b8,b9,":",b10,b11,":",b12,b13,255)
			pause 10
			hi2cout 0,($FE,$C0,b20,b21,b22,":",B14,B15,"/",B16,B17,"/",B18,B19,255)
			pause 10
			

goto main
 
Last edited:

Grogster

Senior Member
Yeah, I agree - the DS1307 or the DS3232 are I2C real-time-clocks, and I would not expect that you could ever set them using standard serial.
You would need to use I2C and the associated I2C commands.

Do you have a link to the module you are using?

The only way I can see that you could program a 1307 or equivalent using serial commands, is if the clock module has it's own serial-I2C interface, which would seem to me to be superfluous - if it uses an I2C interface, then use that.

I've just recently been playing with RTC's, in my case the DS3232, and got caught by the fact that the programming and reading of the clock data is BCD(Binary-coded decimal).
TO read about my issues and the fix offered by others here, read the following thread:
http://www.picaxeforum.co.uk/showthread.php?22211-DS3232-RTC-giving-hours-greater-then-24

EDIT: I read the manual for the LCD/Clock module, and see that it must use an interpreter chip on the clock module to convert the serial to I2C for the clock, so you can ignore what I have written. Still seems odd not to use native I2C, but then, everyone's a critic... ;)
 
Last edited:

MartinM57

Moderator
First short your backup battery for 10-20 seconds. For some reason a fresh cell over volts the i2c bus causing it to reset (thanks nick!)
That is certainly not the universal situation. Standard CR2032 3v cells are normally used and these work straight out of the new packet every time. Shorting batteries like these for 20s will certainly degrade their operating life. Keep the 1307 Vcc at 5v

So what precise battery/ies are you using that needs this agricultural modification (sorry, farmers) to make your circuit work?
 

Grogster

Senior Member
That is certainly not the universal situation. Standard CR2032 3v cells are normally used and these work straight out of the new packet every time. Shorting batteries like these for 20s will certainly degrade their operating life. Keep the 1307 Vcc at 5v

So what precise battery/ies are you using that needs this agricultural modification (sorry, farmers) to make your circuit work?
Yeah, that'd an odd one.
There is 2v of headroom between the 2032 cell voltage and the 5v supply to the RTC chip. I would have thought that it is totally impossible for a 3v cell, to "Over-volt" a 5v supply line... :confused:

The datasheet for the DS3232(page 9) does say that "Backup Power-Supply Input. This pin should be decoupled using a 0.1μF to 1.0μF low-leakage capacitor. If the I2C interface is inactive whenever the device is powered by the VBAT input, the decoupl ing capacitor is not required. If VBAT is not used, connect to ground. Diodes placed in series between the VBAT pin and the battery can cause improper operation. UL recognized to ensure against reverse charging when used with a l ithium battery. Go to www.maxim-ic.com/qa/info/ul. "
 

hippy

Ex-Staff (retired)
First short your backup battery for 10-20 seconds. For some reason a fresh cell over volts the i2c bus causing it to reset
No, that's not the case at all.

The problem seems to have been an AXE033 LCD module being powered with its voltage dropping diode in place. This caused the DS1307 supply rail to be too low to allow I2C operation. The correct solution would have been to short out the voltage dropping diode using the jumper as described in the AXE033 datasheet.
 

nick12ab

Senior Member
First short your backup battery for 10-20 seconds. For some reason a fresh cell over volts the i2c bus causing it to reset (thanks nick!).
No!!! It's as I said earlier! Short the PWR pads - that'll then short out the diode just mentioned by Hippy.

The problem seems to have been an AXE033 LCD module being powered with its voltage dropping diode in place. This caused the DS1307 supply rail to be too low to allow I2C operation. The correct solution would have been to short out the voltage dropping diode using the jumper as described in the AXE033 datasheet.
 

Kecked

Member
Dead nutz on. I missunderstood. I missed that jumper thinking that was done when you run off the batteries and that the diode drop would not matter on 5v. I shorted the diode and it works fine with a fresh battery. I will edit my post so future peolple don't see that error and try it.
 

hippy

Ex-Staff (retired)
Normally the diode drop won't matter at 5V, everything is okay when -

( Input Voltage - Diode Drop ) > ( 1.25 x Battery Voltage )

So nominally -

( 5.0V - 0.7V ) > ( 1.25 x 3V )

4.3V > 3.75V

And with that everything is fine.

If you get a battery that's over 3V and a chip which has a larger multiplier than the nominal 1.25 and you could be up to ( 1.28 x 3.5V ) = 4.48V to have the DS1307 enabled and that's higher than 4.3V after the diode drop.

It's only 0.18V over, and you're pretty unlucky when it doesn't work.
 
Top