Shop OBEX P1 Docs P2 Docs Learn Events
How can I detect a 64KB EEPROM — Parallax Forums

How can I detect a 64KB EEPROM

Bobb FwedBobb Fwed Posts: 1,119
edited 2014-07-30 20:41 in Propeller 1
I have several different pieces of hardware that all run the same software. It all works fine, but recently some versions of the hardware have 64KB EEPROMs. Is there some way (programmatically) to detect the larger EEPROM?

Comments

  • ElectrodudeElectrodude Posts: 1,658
    edited 2014-07-30 13:40
    The non-existent top 32KB of 32KB EEPROMS (i.e $8000 to $FFFF) look the same as the bottom 32KB. You can take advantage of this fact with the following test:

    First read $0000 and $8000. Then write something to $8000 other than what you originally found at $0000 and $8000. Then read $0000. If $0000 has what you wrote to $8000, then you have a 32KB eeprom. If $0000 has what you originally found in $0000, then you have a 64KB eeprom.

    Make sure you put whatever you originally found at $0000 and, if the test finds the EEPROM has 64KB, at $8000, back! This test messes them up, and they probably had something important! $0000 did, at least (clkfreq).
  • Duane DegnDuane Degn Posts: 10,588
    edited 2014-07-30 13:56
    The code attached to post #22 does something like what Electrodude describes.

    The part to detect the size of the EEPROM works but the rest of the code is buggy.
  • Bobb FwedBobb Fwed Posts: 1,119
    edited 2014-07-30 13:58
    The non-existent top 32KB of 32KB EEPROMS (i.e $8000 to $FFFF) look the same as the bottom 32KB.
    I knew the smaller EEPROM "wraps" when you try to write/read too high, and I was thinking about the solution backwards. Thanks, that should work.
  • Bobb FwedBobb Fwed Posts: 1,119
    edited 2014-07-30 14:33
    How about something like this?
    PRI _detectEEPROM | tmp
    
      tmp := $99 ' just some value that is unlikely to already be in the $8000 address (or $0000)
      IF (MEM.read($8000, 1) <> MEM.read($0000, 1))  
        MEM.write($8000, @tmp, 1)
        IF (MEM.read($8000, 1) == tmp)
          RETURN bigEE := true
    
    
      RETURN bigEE := false
    
  • ElectrodudeElectrodude Posts: 1,658
    edited 2014-07-30 15:13
    That could still fail easily. What if $0000 and $8000 both happen to be equal in a 64KB EEPROM? This is a likely scenario for a new EEPROM or one that has another propeller image in it's top 32KB. What if memory location $8000 happens to be $99? It's just as likely to be $99 as anything else.

    Try this:
    PRI _detectEEPROM | lo, hi, newlo, newhi
    
      lo := MEM.read($0000, 1)    ' read $0000
      hi := MEM.read($8000, 1)    ' read $8000
      if lo <> hi                 ' they don't match? it's a 64KB EEPROM
        return bigEE := true
    
      newhi := (lo+1) & $FF       ' newhi <> lo
    { you can uncomment this but kuroneku pointed out that it's unecessary
      if newhi == hi              ' if newhi == hi
        newhi := (hi+1) & $FF     ' then make newhi <> hi (and still <> lo)
                                  ' now new <> lo and new <> hi
    }
      MEM.write($8000, @newhi, 1) ' put new value in $8000
      newlo := MEM.read($0000, 1) ' read value from $0000
      bigEE := (newlo == lo)      ' if $0000 didn't change, it's a big EEPROM
                                  ' if it did change, it should == newhi or else your EEPROM is bad
      if bigEE
        MEM.write($8000, @hi, 1)  ' we messed up $8000, so put it back to how we found it
      else
        MEM.write($0000, @lo, 1)  ' we messed up $0000 (which is the same as $8000 for a small EEPROM), so put it back to how we found it
    
      return bigEE                ' return result
    
  • Bobb FwedBobb Fwed Posts: 1,119
    edited 2014-07-30 15:43
    Awesome. That works great! Thanks a lot!
  • ElectrodudeElectrodude Posts: 1,658
    edited 2014-07-30 16:37
    You're welcome! I don't know if I've ever actually talked to an EEPROM with a Propeller, I just read the forums too much...
  • kuronekokuroneko Posts: 3,623
    edited 2014-07-30 16:49
    PRI _detectEEPROM | lo, hi, newlo, newhi
    
      lo := MEM.read($0000, 1)    ' read $0000
      hi := MEM.read($8000, 1)    ' read $8000
      if lo <> hi                 ' they don't match? it's a 64KB EEPROM
        return bigEE := true
    
    [COLOR="#FF0000"]' At this point we have lo == hi. What do you need the newhi == hi check for?[/COLOR]
    
      newhi := (lo+1) & $FF       ' newhi <> lo
      [COLOR="#FF0000"]if newhi == hi[/COLOR]              ' if newhi == hi
        newhi := (hi+1) & $FF     ' then make newhi <> hi (and still <> lo)
                                  ' now new <> lo and new <> hi
    
      MEM.write($8000, @newhi, 1) ' put new value in $8000
      newlo := MEM.read($0000, 1) ' read value from $0000
      bigEE := (newlo == lo)      ' if $0000 didn't change, it's a big EEPROM
                                  ' if it did change, it should == newhi or else your EEPROM is bad
      if bigEE
        MEM.write($8000, @hi, 1)  ' we messed up $8000, so put it back to how we found it
      else
        MEM.write($0000, @lo, 1)  ' we messed up $0000 (which is the same as $8000 for a small EEPROM), so put it back to how we found it
    
      return bigEE                ' return result
    
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2014-07-30 17:03
    If you are using Tachyon Forth you can just ask using 64K? which returns a true flag if it is >32K. The routine does a temporary save/write/restore to confirm that it does have more than 32K.
    I just tested it over a Telnet connection and it came back "-1 ok"
  • Heater.Heater. Posts: 21,230
    edited 2014-07-30 18:15
    Are you in a hurry to do this?

    Why not just compare the low 32K to the high 32K?
    If they are different it's a 64K device.
    If they are the same it's most likely a 32K device, do the write/read test to be sure.

    This saves a writing to the EEPROM in the majority of cases.

    It relies on address wrap over in 32K devices. Is that always true?
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2014-07-30 18:43
    Heater. wrote: »
    Are you in a hurry to do this?

    Why not just compare the low 32K to the high 32K?
    If they are different it's a 64K device.
    If they are the same it's most likely a 32K device, do the write/read test to be sure.

    This saves a writing to the EEPROM in the majority of cases.

    It relies on address wrap over in 32K devices. Is that always true?

    Yes, the address wraps over but the test is just in case you have an identical image in the top 32K (for some reason) :)
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2014-07-30 18:45
    ... but the test is just in case you have an identical image in the top 32K (for some reason)

    ... which could easily be the case if you're loading to RAM and the EEPROM had never been programmed.

    -Phil
  • ElectrodudeElectrodude Posts: 1,658
    edited 2014-07-30 20:40
    @kuroneko: Because I obviously have no brain... I typed the lo <> hi first but designed the rest in my head first. Thanks.
  • Heater.Heater. Posts: 21,230
    edited 2014-07-30 20:41
    Hence I said "do the write/read test to be sure." in that case.

    It just saves 0.000001% of the life time of the EEPROM in a lot of cases and the 10E-20 chance that the write/read/write test gets interrupted in the middle and corrupts the EEPROM content :)
Sign In or Register to comment.