PDA

View Full Version : I2C storage issue



lerameur
- 19th November 2010, 16:08
hi,

Is it possible to store a value from a ds1307 chip: something like:

time[8]

timer(0) = I2CREAD SDA,SCL,$D1,$00,[STR DB0\8]
.... snip ...
timer(1) = I2CREAD SDA,SCL,$D1,$00,[STR DB0\8]


K

malc-c
- 19th November 2010, 17:21
Not sure if it's what you are after, but (thanks to other forum members) use the following routine to place the data from a DS1307 into variables which are then used to compare set times and alarms, and these are then saved in the memory part of the PIC and recalled in the event of a power failure



I2CRead SDApin,SCLpin,$D0,$00,[RTCSec,RTCMin,RTCHour,RTCWDay,RTCDay,RTCMonth,RTCY ear,RTCCtrl] ; read DS1307 chip

timeH=(RTCHour>>4) 'convert the BCD format of the hours register and store in variable timeH
timeH=(timeH &$03)*10
timeH=timeH+(RTCHour&$0F)

timeM=(RTCMin>>4)
timeM=(timeM &$07)*10
timeM=timeM+(RTCMin&$0F) 'convert the BCD format of the mins register and store in variable timeM

dhouston
- 19th November 2010, 18:05
Or use an ST M41T81 in place of the DS1307. It automatically stores a timestamp whenever it goes on battery power allowing you to track power failure durations.

lerameur
- 19th November 2010, 19:42
The way I see its going towards array and long!!, unless there is another method.
A simpler description of what I am looking is:

I2Cread time1
record time1
...code...
I2Cread time2
record time2
...code...
I2Cread time3
record time3
...code...

So I can keep 100 different times

K