Looking for help understanding reading a value from EEPROM
Don M
Posts: 1,653
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...
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