Auto-Dectect EEProm Size


Closed Thread
Results 1 to 5 of 5

Hybrid View

  1. #1
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    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.

  2. #2
    Join Date
    Dec 2007
    Location
    Paris
    Posts
    101


    Did you find this post helpful? Yes | No

    Default

    I updated Melanie's code which did not behaved as expected on small EEPROMs. Here's the new topic: EEPROM automatic identification routine

Similar Threads

  1. Can't read sequential addresses in external EEPROM
    By tjkelly in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 18th February 2010, 14:46
  2. How to define constants that specify eeprom addresses
    By DwayneR in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 8th December 2009, 04:07
  3. Problem with I2C EEPROM addressing
    By Atom058 in forum General
    Replies: 14
    Last Post: - 3rd November 2009, 03:17
  4. How to write/read strings EEPROM/LCD
    By g-hoot in forum mel PIC BASIC Pro
    Replies: 22
    Last Post: - 11th February 2007, 06:26
  5. word variable to 25lc640
    By TONIGALEA in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 6th July 2004, 19:59

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts