basic_i2c_driver and 24fc1025
nicolad76
Posts: 164
Hi,
I am learning i2c trhough the a/m spin code.
I wrote belowe test code that, of course, doesn't work as expected...do you know what I am doing wrong?
CON
· _clkmode = xtal1 + pll16x
· _xinfreq = 5_000_000
VAR
· byte EEPROM1
· byte EEPROM2
· byte EEPROM3
· byte char
OBJ
· i2c·· : "Basic_I2C_Driver"
· term· : "PC_Interface"
PUB Main
· EEPROM1:= %00000000
· EEPROM2:= %01
· EEPROM3:= %11
·
· term.start(31,30)
· term.str(string("start test"))
· term.out(13)
· term.str(string("init:"))
· term.out(13)
· i2c.Initialize(8)
· term.str(string("write N in EEPROM1"))
· term.out(13)
· char:="N"
··
· if i2c.WriteByte(8,EEPROM1,$0010,@char)
········· term.str(string("write success"))
········· term.out(13)
· else
········· term.str(string("write failed"))
········· term.out(13)
· char:="X"
· term.str(string("read from EEPROM1"))
· term.out(13)
· char:=i2c.ReadByte(8,EEPROM1,$0010)
· term.out(char)
Output is:
start test
init:
write N in EEPROM1
write success
read from EEPROM1
ÿ
Why it does not read correclty? actually I am not even sure it is not writing correctly....helllpppp
thx!
I am learning i2c trhough the a/m spin code.
I wrote belowe test code that, of course, doesn't work as expected...do you know what I am doing wrong?
CON
· _clkmode = xtal1 + pll16x
· _xinfreq = 5_000_000
VAR
· byte EEPROM1
· byte EEPROM2
· byte EEPROM3
· byte char
OBJ
· i2c·· : "Basic_I2C_Driver"
· term· : "PC_Interface"
PUB Main
· EEPROM1:= %00000000
· EEPROM2:= %01
· EEPROM3:= %11
·
· term.start(31,30)
· term.str(string("start test"))
· term.out(13)
· term.str(string("init:"))
· term.out(13)
· i2c.Initialize(8)
· term.str(string("write N in EEPROM1"))
· term.out(13)
· char:="N"
··
· if i2c.WriteByte(8,EEPROM1,$0010,@char)
········· term.str(string("write success"))
········· term.out(13)
· else
········· term.str(string("write failed"))
········· term.out(13)
· char:="X"
· term.str(string("read from EEPROM1"))
· term.out(13)
· char:=i2c.ReadByte(8,EEPROM1,$0010)
· term.out(char)
Output is:
start test
init:
write N in EEPROM1
write success
read from EEPROM1
ÿ
Why it does not read correclty? actually I am not even sure it is not writing correctly....helllpppp
thx!
Comments