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);
}