I've hooked an AT24C256 eeprom/memory chip to Arduino Pro mini.
In my code I check the memory size. It reports 64 allthough I should have 256, why?
Then I erase the eeprom and check that there is nothing at address 32808 (32768-40).
Then I write "Hello world!" to address 40 and check that is got written there. I also check whats at address 32808 an lo an behold it's there too?! Why?
Here is my code.
#include <Wire.h>
#include "SparkFun_External_EEPROM.h"
ExternalEEPROM eep;
void setup()
{
Serial.begin(9600);
delay(10);
Serial.println("I2C EEPROM example");
Wire.begin();
Wire.setClock(400000); //Most EEPROMs can run 400kHz and higher
if (eep.begin() == false)
{
Serial.println("No memory detected. Freezing.");
while (1);
}
Serial.println("Memory detected!");
char koe[13];
char koe2[13];
Serial.print("Mem size in bytes: ");
Serial.println(eep.length());
Serial.println("Erase all");
eep.erase(0);
Serial.print("I read from 32808 (should be empty): ");
eep.get(32808,koe2); //location to read, thing to put data into
Serial.println(koe2);
strcpy(koe,"Hello world!");
Serial.println("Put Hello world! to 40");
eep.put(40,koe); //(location, data)
Serial.print("Now get whats in 40: ");
eep.get(40,koe2); //location to read, thing to put data into
Serial.println(koe2);
Serial.print("Now get what in 32808 (should be empty): ");
eep.get(32808,koe2); //location to read, thing to put data into
Serial.println(koe2);
}
void loop()
{
}
The output is:
I2C EEPROM example
Memory detected!
Mem size in bytes: 64000
Erase all
I read from 32808:
Put Hello world! to 40
Now get whats in 40: Hello world!
Now get what in 32808 (should be empty): Hello world!
I am trying to figure out how to fill the entire eeprom (all 256k) with data and later read it back. The source code of SparkFun_External_EEPROM.h says that
"All read and write restrictions associated with pages are taken care of. You can access the external memory as if it was contiguous."
What am I doing wrong? Why are writes duplicated?