Problem writing to 64k EEPROM
MJHanagan
Posts: 189
I am tring to write some LONG variables to the upper end of the 64k byte EEPROM on my Gadget Gangster Propeller USB board and have problems writing to address $FFF8. I can write to and read a LONG variable starting at $FFFC and one at $FFF4 without any problems but the middle one at $FFF8 always returns a -1 value. Any ideas on what I am doing wrong here?
Here is the basic code:
Here is the result displayed on the serial terminal screen:
[IMG][/img]
[\IMG]
Here is the basic code:
CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 ' MemoryLocation = $7FE0 'Location in memory to store ID. $7FE0 will place at end of eeprom ' EEPROM memory locations for storing last known axis positions and last established origin and status byte. ' For 64k EEPROM: Xabs = $FFFC Yabs = $FFF8 Zabs = $FFF4 Xorg = $FFF0 Yorg = $FFEC Zorg = $FFE8 StatusByte = $FFE4 OBJ i2c : "Basic_I2C_Driver" pst : "Parallax Serial Terminal" VAR byte NewValue long EPSB, AbsPos[3], OrgPos[3], Wally PUB initialize | x, pstCog, OK, ackbit pstCog := pst.Start( 115200 ) pst.Clear pst.Beep pst.str(String(pst#NL, "Serial terminal running in: " ) ) pst.dec( pstCog ) ' Read EEPROM status byte EPSB := i2c.ReadByte(i2c#BootPin, i2c#EEPROM, StatusByte ) pst.str(string(pst#nl, pst#nl, "EEPROM status byte is: %")) pst.bin( EPSB, 8 ) ' IF EPSB == 0 ' pst.str(string( pst#NL, "EEPROM status byte is not valid.")) ' ELSE pst.str(string( pst#NL, "Axis positions from EEPROM: X=")) AbsPos[0] := i2c.ReadLong(i2c#BootPin, i2c#EEPROM, XAbs ) pst.dec( AbsPos[0] ) AbsPos[1] := i2c.ReadLong(i2c#BootPin, i2c#EEPROM, YAbs ) pst.str(string(" Y=")) pst.dec( AbsPos[1] ) AbsPos[2] := i2c.ReadLong(i2c#BootPin, i2c#EEPROM, ZAbs ) pst.str(string(" Z=")) pst.dec( AbsPos[2] ) pst.str(string( pst#NL, "Axis origin positions from EEPROM: X=")) OrgPos[0] := i2c.ReadLong(i2c#BootPin, i2c#EEPROM, XOrg ) pst.dec( OrgPos[0] ) OrgPos[1] := i2c.ReadLong(i2c#BootPin, i2c#EEPROM, YOrg ) pst.str(string(" Y=")) pst.dec( OrgPos[1] ) OrgPos[2] := i2c.ReadLong(i2c#BootPin, i2c#EEPROM, ZOrg ) pst.str(string(" Z=")) pst.dec( OrgPos[2] ) ' Write final position locations to EEPROM. AbsPos[0] := 12345 i2c.WriteLong(i2c#BootPin, i2c#EEPROM, XAbs, AbsPos[0] ) i2c.WriteWait(i2c#BootPin, i2c#EEPROM, XAbs ) AbsPos[1] := 678 Wally :=1357 i2c.WriteLong(i2c#BootPin, i2c#EEPROM, YAbs, AbsPos[1] ) i2c.WriteWait(i2c#BootPin, i2c#EEPROM, YAbs ) pst.str(string(pst#nl, " New Y=")) pst.dec( AbsPos[1] ) AbsPos[2] := 91011 i2c.WriteLong(i2c#BootPin, i2c#EEPROM, ZAbs, AbsPos[2] ) i2c.WriteWait(i2c#BootPin, i2c#EEPROM, ZAbs ) ' Write final position locations to EEPROM. i2c.WriteLong(i2c#BootPin, i2c#EEPROM, XOrg, OrgPos[0] ) i2c.WriteWait(i2c#BootPin, i2c#EEPROM, XOrg ) i2c.WriteLong(i2c#BootPin, i2c#EEPROM, YOrg, OrgPos[1] ) i2c.WriteWait(i2c#BootPin, i2c#EEPROM, YOrg ) i2c.WriteLong(i2c#BootPin, i2c#EEPROM, ZOrg, OrgPos[2] ) i2c.WriteWait(i2c#BootPin, i2c#EEPROM, ZOrg ) EPSB := %10101010 i2c.WriteLong(i2c#BootPin, i2c#EEPROM, StatusByte, EPSB ) i2c.WriteWait(i2c#BootPin, i2c#EEPROM, StatusByte ) pst.str(string(pst#nl, "AbsPos values written to EEPROM")) ' Write final position locations to SC card pst.str(String(pst#NL, pst#NL, "All done." ) )
Here is the result displayed on the serial terminal screen:
[IMG][/img]
[\IMG]
Comments
you got me there - this is brilliant simple. Never thought of it. I really like it.
Thank you
Mike
to this:
and now everything is working as expected.
If the write operation is busy this routine returns a value of 1. When the write operation is done it returns a value of 0.