Woo-hoo!

First posted on 6 November 2002 and somebody is still using the code... gives you a kinda warm glow inside (or is it the Vodka & Lime) and makes it all worthwhile!

This works on the fact that EEPROM Addresses WRAP AROUND... let me explain (since I'm the original author of this ditty)...

You have address 65535... here it is in Binary...

%1111111111111111

When you write DATA to a 64kb EEPROM (24LC512) in this chip you will get your DATA written to that location. But if you had a 32Kb EEPROM (24LC256), it can't see bit 15 and ignores it. All it actions are the lower bits of the address like this...

%0111111111111111

(we're counting from Bit 15 down to and including Bit zero), so it would write your Data into location 32767 and not 65535 because it wraps. So, address 32768 will actually cause a write into address zero in this chip.

So what we are doing is exploiting this feature.

This routine writes the following DATA into the following Addresses...

Address=%1111111111111111 Data=5
Address=%0111111111111111 Data=4
Address=%0011111111111111 Data=3
Address=%0001111111111111 Data=2
Address=%0000111111111111 Data=1

We then do a READ operation for Address 65535... if it's a 24LC512, it will genuinely read-back a 5 from that Address, but a 24LC256 will (expoiting the addressing wrap feature) ignore the top bit and read back from address 32767 and see a 4. A 24LC128, ignores the two top bits from its addressing and will see a 3. A 24LC64 ignores the three top bits and reads back a 2, and a 24LC32 pro-rata reads back a 1.

The routine isn't valid for EEPROMS smaller than a 24LC32 (do people still use those?) because their Page Addressing arangement is different. You need to create a new routine for those baby EEPROMS. Not impossible, just use the same feature demonstrated here.