Shop OBEX P1 Docs P2 Docs Learn Events
Byte storage on eeprom? — Parallax Forums

Byte storage on eeprom?

TCP71TCP71 Posts: 38
edited 2011-04-08 14:19 in Propeller 1
Forgive my ignorance if this has been covered a million times.

I am trying to store a byte or long of data on the eeprom that has my propeller code (24c512 eeprom) for use as a status when the processor is shut down. Basically, I want to be able to access this data to know the status of the unit I'm controlling when it was last shut off and restore it to that mode on boot. Is there a simple way to designate a specific section of eeprom to store this, then I can load it when it boots up and make things the way they were?

Thanks for any help.

Comments

  • davidsaundersdavidsaunders Posts: 1,559
    edited 2011-04-08 09:04
    It would be relatively simple to just store a value at a given address. The bigger question is, how often do you plan on updating the value? There are a limited number of available write cycles in the EEPROM.
  • TCP71TCP71 Posts: 38
    edited 2011-04-08 09:08
    Only when the status of the unit is changed by the user. Not very often. less than 200 time/year. Basically just to "remember" that the unit was running in mode A when it was turned off at night and starts out again in the morning in mode A. 8 bits should cover all the possible variations I need, I just need them to be checked when the unit starts up.

    Thanks.
  • Dave HeinDave Hein Posts: 6,347
    edited 2011-04-08 09:39
    You can use Mike Green's Basic_I2C_Driver object to update a value in in EEPROM. Just use the following code:
    obj
      i2c : "Basic_I2C_Driver"
    
    dat
      status byte 123 ' Initial value
    
    pub main
      i2c.Initialize(28)
      ...
    
    pub UpdateStatus
      i2c.WriteByte(28, $A0, @status, status)
      repeat while i2c.WriteWait(28, $A0, @status)
    
  • TCP71TCP71 Posts: 38
    edited 2011-04-08 11:07
    Thanks, that's quite simple. Is there any way to "lock out" a byte of the eeprom from having it being used during the compiling of code so it is always available and never impacted by the propeller code itself?
  • RaymanRayman Posts: 14,877
    edited 2011-04-08 11:18
    I think the easiest way to do this is with Andy Lindsay's PE Kit Lab App:

    http://forums.parallaxinc.com/forums/default.aspx?f=25&m=219237
  • Mike GreenMike Green Posts: 23,101
    edited 2011-04-08 11:25
    The entire 2nd 32K area in a 64K byte EEPROM is completely untouched by the Propeller Tool. If you only have a 32K byte EEPROM, you can use the end of the EEPROM for storage. It would be very unusual for a Propeller program to use every last byte of the EEPROM and the end ($7FFF and down) is the last to be used. You would lose the stored value when you download a new program to the EEPROM since the ROM bootloader clears the EEPROM to zero when it copies the program from RAM to EEPROM, but you can design your program to handle that case.
  • TCP71TCP71 Posts: 38
    edited 2011-04-08 12:52
    Thank you. so I could use any of the 32k in the high address range of the 64k chip. Unless I actually program new code into the eeprom, my information will remain intact? Accessible via the I2C driver shown above?
    That would be perfect.
  • Dave HeinDave Hein Posts: 6,347
    edited 2011-04-08 14:00
    Yes, you could use any location in the high 32k part of the EEPROM. The prop tool doesn't touch this part of the EEPROM when you reload a program, so your data will remain there. You just need to read the data at the beginning of your program as shown below.

    Dave
    con
      StatusAddress = $8000
    
    obj
      i2c : "Basic_I2C_Driver"
    
    var
      byte status
    
    pub main
      i2c.Initialize(28)
      status := i2c.ReadByte(28, $A0, StatusAddress)
      ...
    
    pub UpdateStatus
      i2c.WriteByte(28, $A0, StatusAddress, status)
      repeat while i2c.WriteWait(28, $A0, StatusAddress)
    
  • TCP71TCP71 Posts: 38
    edited 2011-04-08 14:19
    Thanks!! I will run with this.
Sign In or Register to comment.