At24LC512 memory size

Hey guys, I am a noob here so I need some help with 24lc512 eeprom which I am using with my arduino board.

In the datasheet it is mentioned that 24lc512 can store 512kbits of data i.e. 64kBytes. This means the total number of places in which we can store our data is 64000 (0 - 63999).

Technically, if I try to store in a place whose address is larger than 63999, it should overwrite the bytes from start or do something unexpected. But what happens is that even when I write some data in a cell address greater than 63999 (let's say 75000), it writes the data over there perfectly. I have also verified this by reading the whole eeprom (via loop) and printing it out on the serial monitor, it gives me perfectly written data on each address.

Now what I want to ask is, why can I write on a cell address greater than 63999 and why does the 24lc512 does not behave unexpectedly. What is the actual size of this eeprom chip? How can it be possible that I am able to write data of more than 64k bytes on it?

Here is my code to help you better understand my query.

#include <Wire.h>

#define chipAddress1 81

void writeTo(int chAddress, unsigned long ceAddress, byte wData)
{
  Wire.beginTransmission(chAddress);
  Wire.write((long)(ceAddress >> 8));    //MSB
  Wire.write((long)(ceAddress & 0xFF));  //LSB
  Wire.write(wData);
  Wire.endTransmission();
  delay(5);
}

byte readFrom(int chAddress, unsigned long ceAddress)
{
  Wire.beginTransmission(chAddress);
  Wire.write((long)(ceAddress >> 8));    //MSB
  Wire.write((long)(ceAddress & 0xFF));  //LSB
  Wire.endTransmission();
  Wire.requestFrom(chAddress, 1);
  byte rData;
  if (Wire.available())
  {
    rData = Wire.read();
  }
  return rData;
}

void updateTo(int chAddress, unsigned long ceAddress, byte wData)
{
  if ((readFrom(chAddress, ceAddress)) != wData)
  {
    writeTo(chAddress, ceAddress, wData);
  }
}

void setup()
{
  Serial.begin(9600);
  Wire.begin();

  Serial.println("Serial data initialized");
}

void loop()
{
  writeTo(chipAddress1, 75000, 9);

  for (unsigned long i = 0; i < 512000; i += 25)
  {
    Serial.print(i); Serial.print("  ");
    byte x = readFrom(chipAddress1, i);
    Serial.println(x);
  }

  while (1);
}

sp. "0 to 65535"

1 Like

As @anon73444976 said, the last valid address is 65535 (2^16 - 1). If you write to address 65536, I expect that will be equivalent to writing to address 0, writing to address 65537 equivalent to writing to address 1 and so on. That is because only 16 bits of address are available when communicating with the chip. Even though your code uses "long", these code lines

  Wire.write((long)(ceAddress >> 8));    //MSB
  Wire.write((long)(ceAddress & 0xFF));  //LSB

loose bits 16 to 31 of the long, they are not, and can not, be sent to the chip.

1 Like

And 1kByte is 1024bytes

1 Like

"1Kibyte"

1 Like

Thanks man. Really appreciate the description.

Thanks man!

I was considering kByte as 1000 bytes and not as 1024 bytes. That got me.

I noticed it! I was reading this post when you abruptly stole it from me before my eyes.

haha just after posting it, I realized where I was wrong. So deleted it. :sweat_smile:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.