Microchip Application Notes should really be taken with a liberal pinch of salt. Use them as a guide only as to the theory of what you're trying to achieve. Beyond that a lot of them are seriously misleading and erroneous.
OK... I've thrown this together... deliberately written in a long-winded fashion so you can follow the code... try it... see what happens...
Code:
Address var Byte
CounterA var Byte
EpromType var Byte
Control var Byte
For CounterA= 5 to 1 Step -1
Address=%11111111
Control=%10100000
If CounterA=5 then Control=%10101110
If CounterA=4 then Control=%10100110
If CounterA=3 then Control=%10100010
If CounterA=1 then Address=%01111111
I2CWRITE SDA,SCL,Control,Address,[CounterA]
Pause 10
Next CounterA
Address=%11111111
Control=%10101110
I2CRead SDA,SCL,Control,Address,[EpromType]
If you want to know where I got the figures from, just look at the table in the I2CREAD command in the PBP manual.
This should write a byte in the last memory location of each of the five sizes of chip...
Into a 24LC16 at address 2047 it will write a 5
Into a 24LC08 at address 1023 it will write a 4
Into a 24LC04 at address 511 it will write a 3
Into a 24LC02 at address 255 it will write a 2
and into a 24LC01 at address 127 it will write a 1
Naturally if you have a 24LC16 you will end up writing into five memory locations, at each of the addresses. A 24LC08 will have four memory locations written to... with the one at 1023 being written to twice... first with a 5 then overwritten with a 4. The 24LC04 will have three addresses written to, but it's top one will be written to three times, first with a 5, then with a 4 and finally with a 3. The 24LC01 will only have one address written to, but it will be written five times, first with a 5, then a 4... etc until finally it gets a 1.
When reading back, by selecting Address 2047, chips that cannot access that high will read-back the highest memory address that they can (ignoring the higher bits), and in so doing so, the variable EpromType will hold the number identifying the type of chip you've got installed.
Like I mentioned in my original reply, all we've done is taken the same routine and principals and rehashed them for the Page addressing of the baby sized EEPROMs.
I'm sure you can test this and report back if it works, as unfortunately I don't have anything smaller than a 24LC64 in stock.
ooops... found a small error in the code which I corrected this morning 7am 17 June, so anyone copying the code before that please check.
Bookmarks