Help using i2c and external memory (AT24C256)

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.println("I2C EEPROM example");

  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("Erase all");
  Serial.print("I read from 32808 (should be empty): ");
  eep.get(32808,koe2); //location to read, thing to put data into

  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.print("Now get what in 32808 (should be empty): ");
  eep.get(32808,koe2); //location to read, thing to put data into

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?

It's a 256 kilobit memory, hence 32768 bytes

Ah the 256k here is bits not bytes! The SparkFun_External_EEPROM eep.length() function reports 64000 for some reason.
Thank you for the explanation.

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