Looking for help understanding reading a value from EEPROM
I have a value of 0001450 stored at location $9000. In my initialization code I am trying to read the value from this memory location to set an initial value in a display. When I run my code I get the value of 000006 in the display.
Here's a bit of the code in question:
I changed the line from newlevel := level.read to newlevel := i2c.readlong(28, $A0, $9000) to read the value from memory.
I have another little test program I wrote to store and read a number from the location and I know it is stored there. It stays there after a re-flash of the propeller.
What have I done wrong here?
Thanks.
Don
Here's a bit of the code in question:
pub main | newlevel, oldlevel, Pressed_Key, InitVal, memvalue
term.start(31, 30, %0000, 115_200) ' start terminal for test
pause(2000)
term.tx(CLS)
i2c.initialize(28)
level.init(16, true, 0, 1707, 0) ' detented encoder on p16/p17
i2c.start(28)
vfd.Init( E, RS, RW, DBHigh, DBLow )
kp.start(4, 4, 0, 4, @table) ' start keypad driver
pause(1)
'newlevel := level.read ' read initial value
newlevel := i2c.readlong(28, $A0, $9000) ' read value from EEPROM
vfd.clear ' clear vfd screen
term.str(string("Table Controller", 13))
term.str(string("Version 0.07"))
vfd.PrintStr(string("Table Controller"))
vfd.SetRowCol(2, 0)
vfd.PrintStr(string("Version 0.07"))
pause(4000)
vfd.clear
term.tx(CLS)
term.tx(LF)
term.str(string("Press PROG for Menu"))
vfd.SetRowCol(2, 0)
vfd.PrintStr(string("Press PROG for Menu"))
repeat
oldlevel := newlevel ' setup to detect change
term.tx(HOME) ' display it
vfd.SetRowCol(0, 0)
vfd.PrintStr(string("Position: "))
term.str(string("Position: "))
'vfd.SetPos(10)
'InitVal := i2c.ReadLong(28, $A0, $9000)
'vfd.PrintStr(simp.decf(InitVal, 4))
vfd.SetPos(16)
vfd.PrintChr($22)
newlevel *= 3515
newlevel /= 100
term.decdp(newlevel, 4)
vfd.SetPos(10)
vfd.PrintStr(simp.decf(newlevel, 4))
I changed the line from newlevel := level.read to newlevel := i2c.readlong(28, $A0, $9000) to read the value from memory.
I have another little test program I wrote to store and read a number from the location and I know it is stored there. It stays there after a re-flash of the propeller.
What have I done wrong here?
Thanks.
Don

Comments
The initialize routine puts the i2c bus in a known state. In the case of pasm_i2c_driver it starts up a PASM cog. This is a bit confusing because most objects use the start method to start up a cog. In this case, the start method sends a start bit to the i2c device.
Here's the code I wrote to test storing and reading a value to EEPROM...
con _clkmode = xtal1 + pll16x ' _xinfreq = 5_000_000 _clkfreq = 80_000_000 MS_001 = _clkfreq / 1_000 con #1, HOME, #8, BKSP, TAB, LF, CLREOL, CLRDN, CR, #16, CLS ' PST formmatting control obj i2c : "Basic_I2C_Driver_1" pst : "Parallax Serial Terminal" var pub main | InitVal, oldval pst.start(115_200) pause(2000) pst.clear i2c.initialize(28) i2c.start(28) pst.str(string("Initial value stored in EEPROM: ")) oldval := i2c.readlong(28, $A0, $9000) pst.hex(oldval, 8) pst.chars(pst#NL,2) pst.str(string("Enter 8 digit number ")) InitVal := pst.hexin pst.hex(initval, 8) pst.chars(pst#NL,2) i2c.writelong(28, $A0, $9000, initval) reboot pub pause(ms) | t t := cnt repeat ms waitcnt(t += MS_001)I worked this up real quick in the hotel room. I haven't actually tested it, but I've messed with writing to the EEPROM before and everything looks right. Give this code a try and see if it works for you. It has been derived from the code we looked at while at UPEC.
Thanks,
Daniel
Your code works. I'll see if I can work in your logic to my code and make mine work. Thanks!
Thanks everyone