PDA

View Full Version : ds1307 i2c



tamertokgoz
- 13th June 2008, 06:41
Hii.

I wanna ask a question :

How can I stop reading from ds1307 and start writing to eeprom on the same sda scl line and after writing start reading from ds1307 again

sinoteq
- 13th June 2008, 08:43
Hi
Each device you connect to a I2C bus has a 7 bit device address that is set from the factory, some chips has address pins that can be grounded or tied to VDD for additional addressed. Example:

Eeprom has 1010000 as the generic address with all address pins grounded but you can have many EE2 on the same I2C line if each chip has it's own address. 1010000, 1010001,1010010,1010011 and so on, in the datasheet for each component it is stated how many you can have on the same I2C bus.

The address to DS1307 is 11010000 7 bits and the last bit is used by PBP to set read or write. Let us say we have 3 chips on one I2C bus, one eeprom, one RTC and one sound chip. The device id is as below.

EE2=%10100000
RTC=%11010000
ISD=%10000000

To write the the RTC do like this:
I2C_Adr_B=0
I2CWRITE SDA,SCL,RTC,I2C_Adr_B,[0,0,0,0,0,0,0,0]


I2C_Adr_W=0
I2CREAD SDA,SCL,EE2,I2C_Adr_W,[I2C_Data(0),I2C_Data(1),I2C_Data(2),I2C_Data(3)]

as long as the device ID are different you can have as many chips as you like on the same I2C lines (more or less anyway)

Look at http://www.8052.com/sbc/schematics/DS1307.pdf PAGE 8 and you can see what the datasheet has to say about this.

Understand?

tamertokgoz
- 13th June 2008, 09:29
the problem is that I can read data and also I manage to send data to eeprom and ds1307
but sometimes is says data collision and reset program ...
it does nor importtant how long I use pause 10 20 50 does not matter ...




i2cread SDA,scl,$D0,0,[sec,mnt,hour,day,month]
pause 25
if amper>8 then
Adres = Adres +4


I2CWRITE SDA,SCL,$A0,Adres,[hour,mnt,sec,amper],hatavar

pause 25
endif

hatavar:
LCDOut $fe,1, "wrt timed out" ' I2C command timed out
Pause 100
RETURN

Jerson
- 13th June 2008, 11:11
Hii.

I wanna ask a question :

How can I stop reading from ds1307 and start writing to eeprom on the same sda scl line and after writing start reading from ds1307 again

This looks like interrupt based operation of DS1307 to read the RTC. You cannot do this. What you can do is set a bit variable while you are reading the rtc and use this to avoid writing to the eeprom.

tamertokgoz
- 13th June 2008, 11:28
This looks like interrupt based operation of DS1307 to read the RTC. You cannot do this. What you can do is set a bit variable while you are reading the rtc and use this to avoid writing to the eeprom.

the program was written : for to measure frequency and amper and if it is greater then desired value write it to the eeprom. it will be a logger

tamertokgoz
- 13th June 2008, 12:48
ADD VAR WORD
ADDO VAR WORD
FX VAR WORD


sec var byte
mnt var byte
hour var byte
day var byte
month var byte
year var byte

BOOT:
LCDOut $fe, 1

LCDOut " "

LCDOut $fe,$c0," "
pause 1000
ADD =10




LOOP:

i2cread SDA,scl,$D0,0,[sec,mnt,hour,day,month]

pause 225

LCDOut $fe, 1
Lcdout hex2(hour),hex2(mnt),hex2(Sec), "-", hex2(day),".", hex2(month),"."

LCDOut $fe,$c0,"Okudum Yazcam"

ADD = ADD +1
I2CWRITE SDA,SCL,$A0,ADD,[ADD]',BOGUS
PAUSE 250

IF BTN1 THEN OKU
GoTo loop ' Do it forever
OKU :
FOR ADDO =10 TO ADD
I2CREAD SDA,SCL,$A0,ADDO,[FX]',BOGUS2
PAUSE 25
SEROUT2 So,84,[DEC ADDO ,"--", DEC(FX), 13,10]
PAUSE 50

NEXT
GOTO LOOP
bogus:
LCDOut $fe,1, "wrt timed out" ' I2C command timed out
Pause 100
RETURN

bogus2:
LCDOut $fe,1, "read timed out" ' I2C command timed out
Pause 100
RETURN

End

Jerson
- 13th June 2008, 15:26
Your program is writing continuously to the eeprom. Totally unadvisable. If you have to do it this way, at least slow it down to around 1 write every minute. The interrupt operation I was suspecting is ruled out after seeing your code. I feel your frequent writes may have damaged the eeprom by now.