almost there

Kecked

Member
Ok I finally set my clock and it is running. I can see the time as well (I gave up on the date and day for now)
Here is my last issue to solve. The display flashes between the correct time and ??:??:??. If I set the setfreq to M32 I can make out the time inbetween the ??.
What I think happens is that when the i2c bus is switched to read the next time in the variables i nthe bdctoascii become indeterminate or some such thing.
HEre is my question. What command makes the display stay put until I tell it to update again when I call the i2cslave command again?

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

'Set Clock
#picaxe 18m2
#no_data
setfreq m32
Pause 500

	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    	= $17	
	Let mins    	= $07	
	Let seconds 	= $00	
 	Let control 	= %00010000 ; Enable output at 1Hz
#endrem
 	
'Write to Clock on I2C Bus	
 	
 	'hi2csetup i2cmaster, %11010000, i2cslow,i2cbyte
 	'writei2c 0, (seconds, mins, hour, day, date, month, year, control)
 	
Main:

'Readout Clock on I2C Bus
	
	i2cslave %11010000, i2cslow_32,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
 
'Send to LCD

		i2cslave $C6,i2cslow_32,i2cbyte
		hi2cout 0,($FE,$80,b8,b9,":",b10,b11,":",b12,b13,255)
		
		
goto main
 

nick12ab

Senior Member
The display 'stays put' until you update it. The question marks indicate a value of '255' being used with the bintoascii command and this must be appearing due to a problem in your code or hardware.
  1. Why aren't you using i2cslow_32 at the beginning when writing to the DS1307? Whilst that probably isn't the cause of your problem, it should be set ti i2cslow_32.
  2. Is the backup battery fitted? If a floating signal makes the battery voltage more than a certain amount then the i2c connection to the DS1307 is shut off.
 

g6ejd

Senior Member
Why are you sending 255 to the display? Does the controller need it? Try the code without that 255.
 

Kecked

Member
reply

Possibly because the AXE033 requires it?
Ok here you have it. I did the clock set first before I went to setfreq m32 and had it rem'd out so I forgot to change it when I posted it.

The write and hi2cout commands require a 255 at the end of every line

I am starting to suspect I have something wrong in hardware because I did check the battery and even changed it and even after the ds chip is set when I try to put the axe033 into clock mode it is all zeros. Guess I have to go serial and use a sepaparate ds1307 on its own bus. Was trying to avoid it but this isn't working out.

Nick. I am using a 5v regulated power supply from a breadboard so it should be solid. But you made me think. I have all the pins floating that are not used on the micro. I am only using the sclk and scda for the i2c and except for the c.5 tie everything else is floating. Should I ground all the other pins?
 

Kecked

Member
I GOT IT AND NICK WAS RIGHT! I took the backup battery out and low and behold it works fine. So How do I fix that issue?
 

nick12ab

Senior Member
So How do I fix that issue?
I'd totally forgotten - whatever genius designed the AXE033 decided to stick in a diode (with 0.7V voltage drop) in series with the entire AXE033 module and this means that the DS1307 shuts off the i2c bus because the power supply voltage isn't high enough. You can fix the problem properly by shorting the PWR holes on the AXE033 and then you should be able to use the backup battery.
 

Kecked

Member
now comes the hard part or at least tedious part of calibrating the meters to read linearly. I think it is time to learn how to store and read tables! Unfortunately none of the meters I have since they are vintage 1950's works real well so I will have to output a duty cycle to make the meter read as I wish for each number. It will be worthwhile. Then I have to design the sunrise sunset code to drive rgb leds to simulate sunrise and sunset. I could do thta with a simple lookup table but I want to try a math coprocessor to do the actual math. (needs csc, ctan and other wierd stuff). That will be on separate chips. IE the i2c will tell the other chip what time it is and then decide to start or end the cycles.

This will be used to get clams to spawn. They are sensitive to light and only spawn at one exact time each year and they know if you try to fool them so it has to be accurate or they will not spawn. I even have to simulate that moon rise and set. So one project flows into the next. By the time i am done I'll be able to use eeproms, mathcoprocessors, i2c bus sensors, lcds, digital pots.....IE I'm just getting started!
 

papaof2

Senior Member
Remember to add some type of backup power and time/date verification. Missing the time for surfing a big wave isn't critical, but missing spawn time will be fatal for your project. This isn't a new idea - the Apollo space flights used three computers and needed agreement from two of them to consider data valid.
 

nick12ab

Senior Member
Have you read my last post? Also if there's no battery fitted, floating signals could cause the DS1307 to not work correctly which can be fixed by shorting the battery contacts with a high value resistor.
 
Top