Shop OBEX P1 Docs P2 Docs Learn Events
Looking for help understanding reading a value from EEPROM — Parallax Forums

Looking for help understanding reading a value from EEPROM

Don MDon M Posts: 1,653
edited 2011-06-27 13:59 in Propeller 1
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:
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

  • Dave HeinDave Hein Posts: 6,347
    edited 2011-06-26 18:09
    Get rid of the i2c.start(28). The i2c objects contain high level and low level methods. The high level methods read and write bytes, words, longs and blocks. The low level methods read and write bits and send start and stop bits. The start routine is a low level routine that you shouldn't normally have to call.

    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.
  • Don MDon M Posts: 1,653
    edited 2011-06-26 18:16
    Ok I'll try that.

    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)
        
    
  • Don MDon M Posts: 1,653
    edited 2011-06-26 18:19
    Changing that did not help.
  • Daniel HarrisDaniel Harris Posts: 207
    edited 2011-06-26 19:21
    Hey Don,

    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. :D

    Thanks,
    Daniel
  • Don MDon M Posts: 1,653
    edited 2011-06-26 19:34
    Hey Dan,

    Your code works. I'll see if I can work in your logic to my code and make mine work. Thanks!
  • Don MDon M Posts: 1,653
    edited 2011-06-26 20:04
    I tried adding your read statement to my code and still nothing. I must be messed up with the type of number (dec or hex) I am trying to store and read. I am not sure which way to go...
  • kuronekokuroneko Posts: 3,623
    edited 2011-06-26 20:09
    Don M wrote: »
    I tried adding your read statement to my code and still nothing.
    If you display the value immediately after the newlevel := i2c.readlong() by using e.g. term.hex(newlevel, 8) what do you get? And you do have a 64K EEPROM installed (a 32K one simply wraps the address)?
  • Don MDon M Posts: 1,653
    edited 2011-06-26 20:34
    Yes there is a 64K chip on the board (AT512). I inserted your line right after the assingment and it displays the same data on the PST as what I stored in the EEPROM.
  • kuronekokuroneko Posts: 3,623
    edited 2011-06-26 20:41
    Don M wrote: »
    Yes there is a 64K chip on the board (AT512). I inserted your line right after the assingment and it displays the same data on the PST as what I stored in the EEPROM.
    So now find the place where it gets corrupted. What does this value represent anyway? Note that you scale newlevel later before you actually display it (*3515/100).
  • Don MDon M Posts: 1,653
    edited 2011-06-27 13:59
    Ok. I got it working or at least I better understand it now. It looks like it was a combination of the way I was reading (interpreting) the stored number, the method I was using to read and write to the EEPROM and along with applying the multiplier. So now I can store a number (in HEX), retrieve it in my program and once it goes through the math the correct data displays.

    Thanks everyone
Sign In or Register to comment.