Shop OBEX P1 Docs P2 Docs Learn Events
Checking for Empty value? — Parallax Forums

Checking for Empty value?

eagletalontimeagletalontim Posts: 1,399
edited 2012-12-02 16:04 in Propeller 1
I am trying to figure out how to properly check a variable to see if it is "empty". This function is for reading the EEPROM and if the values received are "empty", load default values. Please note that some values will equal 0


Here is what I have so far :
CON 
    menuItems = 11

VAR
    BYTE Stored[255] 

PUB Main | iloop, EValue
    repeat iloop from 0 to menuItems Step 1
        EValue := ReadEEPROM(iloop)
        ' HERE is where I need to check if EEPROM was loaded
        Stored[iloop] := EValue

    if NOT_LOADED == 1
        Load_Defaults    

PUB saveval(value, address) | startTime
  if i2c.WritePage(i2c#BootPin, i2c#EEPROM, $8000 + (address * 32), @value, 32)
    abort ' an error occured during the write
  startTime := cnt ' prepare to check for a timeout
  repeat while i2c.WriteWait(i2c#BootPin, i2c#EEPROM, @value)
    if cnt - startTime > clkfreq / 10
      abort ' waited more than a 1/10 second for the write to finish
  return

PUB ReadEEPROM(address) | tmp
  tmp := i2c.ReadLong(i2c#BootPin, i2c#EEPROM, $8000 + (address * 32))
  return tmp

Comments

  • MagIO2MagIO2 Posts: 2,243
    edited 2012-12-02 09:49
    In another thread you said that the values will be lower than 255, so you could use 255 as an empty marker.
  • Mike GreenMike Green Posts: 23,101
    edited 2012-12-02 09:49
    There is no "empty" value. EEPROMs combine an erase cycle which sets the memory cells to ones with a write cycle that changes some of the cells to zeros. Flash memories separate the two functions into individual erase and write zeros operations. You may find EEPROMs erased to one bits from the factory, but that's not guaranteed. I would suggest allowing an additional byte in your parameter table and setting it to the 8-bit simple checksum modulo 254 + 1 of the data in the parameter table. A checksum byte value of all zeros or ones would be invalid and this would provide a pretty good check for the validity of the other bytes in the table.
  • Clive WakehamClive Wakeham Posts: 152
    edited 2012-12-02 15:56
    MagIO2 wrote: »
    In another thread you said that the values will be lower than 255, so you could use 255 as an empty marker.

    I think his quote meant to infer that the values would be 8 bits or less....

    (At least to me it does....)
  • Clive WakehamClive Wakeham Posts: 152
    edited 2012-12-02 16:04
    I am trying to figure out how to properly check a variable to see if it is "empty". This function is for reading the EEPROM and if the values received are "empty", load default values. Please note that some values will equal 0 ]

    You might need to have your values stored in two different locations in the EEPROM, and if those locations don't match then basically the original spot is empty.

    Or have the secondary locations store a set value to indicate if it the original location has been updated from the "default" value.

    Or have all locations word sized (16 bits) with the first byte storing a fixed set value (say $FF) and then the next value the true value.
Sign In or Register to comment.