ATMEL 24C02 EEPROM - Trouble understanding how the addressing works

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 ...
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

• There is a 24CXX chip variant that uses all eight addresses by itself, and thus looks like 8 small chips on the I²C bus. Check your chips markings. – Turbo J Jul 9 '18 at 8:45
• You do not write the addresses; you hardwire them. – Peter Smith Jul 9 '18 at 8:46
• @TurboJ The chip says the following: "ATMEL 611, 24C02, PU27" – user193111 Jul 9 '18 at 8:49
• @PeterSmith Sorry, I'm completely new to I2C. Can you explain what hardwiring is? – user193111 Jul 9 '18 at 8:51
• @pixelomer Connecting them directly to GND or VCC is called Hardwiring and not changing them using software – MaNyYaCk Jul 9 '18 at 8:52

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:

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

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.

• By writing to pins, I mean setting pins to HIGH or LOW. In Arduino, the function that does this is digitalWrite. That's why I said "write". – user193111 Jul 9 '18 at 9:10
• But as I said normally you would never try to setup a 24C02 to have its A0, A1 and A2 pins tied to GPIO's. Instead just connect them either to GND or to VCC. If you just have one 24C02 then you would connect all three of those pins to GND as 000b. Then when you want to write to the part use an address byte of 0xA0 and when you want to read use an address byte of 0xA1. (continued) – Michael Karas Jul 9 '18 at 9:23
• (continued from above) If you then had a second 24C02 you would connect its A0 to VCC and its A1 and A2 to GND for value 001b. Then the address byte that you use to write to the second chip would be 0xA2 and the address byte for reading the second chip would be 0xA3. (continued) – Michael Karas Jul 9 '18 at 9:24
• (continued from above) If you then had a third 24C02 you would connect its A0 and A2 to GND and its A1 and A1 to VCC for value 010b. Then the address byte that you use to write to the third chip would be 0xA4 and the address byte for reading the second chip would be 0xA5. Etc Etc. – Michael Karas Jul 9 '18 at 9:26
• I tried. Can't change the values dynamically. It will answer to address that was set up before powering up. – MaNyYaCk Jul 13 '18 at 6:22

Pins A0:A2 are used for creating the address.

So for example you keep A0 : Low , A1: High and A2: Low, your address will be 1010010 + R/W.

The device will not respond to the address that is being set dynamically. It considers the value of the A0,A1 and A2 before the power up and sticks to it till reset.

• Can you give more information? For example, which pin do I need to turn HIGH/LOW in order to make the EEPROM use only one address? – user193111 Jul 9 '18 at 8:41
• if you are gonna control them using the software, you need to change all the three i.e A0,A1 and A2. But my suggestion would to directly connect them to ground or VCC for the addressing scheme. – MaNyYaCk Jul 9 '18 at 8:49
• After you all said changing EEPROM address with GPIO is not a good idea, I decided to hardwire from 5V and GND to A0, A1 and A2. Maybe the issue is setting the address after power on. I will try in about an hour. – user193111 Jul 9 '18 at 9:38