Electronic – arduino – ATMEL 24C02 EEPROM – Trouble understanding how the addressing works

arduinoatmeldatasheeteepromi2c

I am currently writing a library for ATMEL's 24C series EEPROMs (not a programming question). The library works fine with a single EEPROM at the moment and I am trying to support multiple EEPROMs now, since according to the data sheet, up to 8 24C02 EEPROMs can be connected at the same time. However, I am not able to understand how to assign an address to the EEPROM. From what I understand, I can assign an address between 0x50 and 0x57 by setting A0, A1 and A2 pins to HIGH or LOW. However, it doesn't matter what I set these pins to. The EEPROM uses all the 8 addresses:

I2C scanner. Scanning ...
Found address: 80 (0x50)
Found address: 81 (0x51)
Found address: 82 (0x52)
Found address: 83 (0x53)
Found address: 84 (0x54)
Found address: 85 (0x55)
Found address: 86 (0x56)
Found address: 87 (0x57)
Done.
Found 8 device(s).

This output is from I2C scanner. I can transmit with all of the addresses and the single EEPROM receives it all. Is there something else I need to do?

Here is the datasheet of the EEPROM: https://www.rhydolabz.com/documents/24c04.pdf

Best Answer

Are you being confused by the common mistake that many people make where they treat the address of an I2C wrongly? Some parts will refer to the address as a 7-bit quantity that does not include the R/W bit. Others will refer to the address as an 8-bit quantity that includes the R/W bit. Even the data sheet that you linked can lead to confusion in this regard. In figure 4 they refer to the address as an 8-bit quantity:

enter image description here

And in the immediately following figure 5 they refer to the address as the 7 bit quantity from MSB to LSB:

enter image description here

Also be aware that the A0 to A2 pins on the device package are meant to remain static in a design. If a total of eight 24C02's are used in the design then each of the devices will have these three pins hard strapped in a different combination from the set of 000b, 001b, 010b, 011b, 100b, 101b, 110b and 111b. When you say that you are "writing" to the pins this does not make clear exactly what you are doing. Normally there is no writing to the 24C02 pins. Instead the three bits that you supply out on the interface in the device address field must match the hard strapped values on the pins in order for the device to be selected.

If by chance you had decided to add some other MCU GPIOs that tied to the A0, A1 and A2 pins on a single device that would really not be a valid usage scenario. On top of that I have never been sure that it is even possible to dynamically change the strapped value on the A0, A1 and A2 pins of a 24C02 after it has powered up.