2
\$\begingroup\$

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

\$\endgroup\$
  • \$\begingroup\$ 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. \$\endgroup\$ – Turbo J Jul 9 '18 at 8:45
  • \$\begingroup\$ You do not write the addresses; you hardwire them. \$\endgroup\$ – Peter Smith Jul 9 '18 at 8:46
  • \$\begingroup\$ @TurboJ The chip says the following: "ATMEL 611, 24C02, PU27" \$\endgroup\$ – pixelomer Jul 9 '18 at 8:49
  • \$\begingroup\$ @PeterSmith Sorry, I'm completely new to I2C. Can you explain what hardwiring is? \$\endgroup\$ – pixelomer Jul 9 '18 at 8:51
  • \$\begingroup\$ @pixelomer Connecting them directly to GND or VCC is called Hardwiring and not changing them using software \$\endgroup\$ – MaNyYaCk Jul 9 '18 at 8:52
2
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ 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". \$\endgroup\$ – pixelomer Jul 9 '18 at 9:10
  • 3
    \$\begingroup\$ 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) \$\endgroup\$ – Michael Karas Jul 9 '18 at 9:23
  • 2
    \$\begingroup\$ (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) \$\endgroup\$ – Michael Karas Jul 9 '18 at 9:24
  • 2
    \$\begingroup\$ (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. \$\endgroup\$ – Michael Karas Jul 9 '18 at 9:26
  • \$\begingroup\$ I tried. Can't change the values dynamically. It will answer to address that was set up before powering up. \$\endgroup\$ – MaNyYaCk Jul 13 '18 at 6:22
1
\$\begingroup\$

Pins A0:A2 are used for creating the address. Addressing Scheme

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.

\$\endgroup\$
  • \$\begingroup\$ 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? \$\endgroup\$ – pixelomer Jul 9 '18 at 8:41
  • \$\begingroup\$ 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. \$\endgroup\$ – MaNyYaCk Jul 9 '18 at 8:49
  • \$\begingroup\$ 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. \$\endgroup\$ – pixelomer Jul 9 '18 at 9:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.