Shop OBEX P1 Docs P2 Docs Learn Events
basic_i2c_driver and 24fc1025 — Parallax Forums

basic_i2c_driver and 24fc1025

nicolad76nicolad76 Posts: 164
edited 2008-04-01 03:13 in Propeller 1
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!

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-04-01 03:13
    You have to allow the EEPROM to finish writing before you try to read from it. You can either call WriteWait (see the comments in the object) or always wait 5 to 10ms after writing.
Sign In or Register to comment.