EEPROM anomaly

I got some time tonight to run a more extended test on my EEPROM setup to really see if it will write correctly to all three 24FC512 EEPROMs.

My setup:

The code is below.

So the program is setup to write data across the 3 EEPROMs until it fills all available space. The program creates 300 records at a time and loops for 66 times. This will create 19800 records which is 141 records more than the maximum allowable amount of 19659. The total number of records available is a function of the total memory size of the 3 EEPROMs and the size of my data structure. The test will be to see if it writes correctly to the 3 EEPROMS and what it will do when it runs out of addressable space.

I uploaded the code and let it start cranking. Building the random data takes some time so I was prepared to wait.

So far so good......but wait my data looks corrupted.

But it still is exhibiting a discernable pattern. But wait.....the pattern changed again.

Hmmm....I wonder why it doesnt write the data correctly. It is writing to valid addresses on the EEPROM, but the data has gotten jumbled and isn't printing out correctly. This will need some investigation. My initial guess is it is running into problems when it meets the address boundaries between the separate EEPROMs.

The code:

Extended Database Library + 24XX512 EEPROM Demo Sketch

The Extended Database library project page is here:

The E24C1024 library project page is here:

#include "WProgram.h"

// Use the 24XX512 EEPROM as storage
#include // Should be compatible with 24XX512 series in this instance

// From the 24XX512 datasheet:
// The Chip Select bits A2, A1 and A0 can be used to expand the
// contiguous address space for up to 4 Mbit by adding up to eight
// 24XX512 devices on the same bus.
// So, each device must be have their address pins wired as listed below to
// create a single, contiguous address space across one or more devices.
// Example - 1 device:
// Device connections: A0->GND, A1->GND, A2->GND
// Uncomment only the #define TABLE_SIZE 65536 line below.

// Example - 3 devices:
// Device 1 connections: A0->GND, A1->GND, A2->GND
// Device 2 connections: A0->+5V, A1->GND, A2->GND
// Device 3 connections: A0->GND, A1->+5V, A2->GND
// Uncomment only the #define TABLE_SIZE 196608 line below.
// Uncomment the ONE line appropriate for your platform.
//#define TABLE_SIZE 65536 // 1 device: A0->GND, A1->GND, A2->GND
//#define TABLE_SIZE 131072 // 2 devices: A0->+5V, A1->GND, A2->GND
#define TABLE_SIZE 196608 // 3 devices: A0->GND, A1->+5V, A2->GND
//#define TABLE_SIZE 262144 // 4 devices: A0->+5V, A1->+5V, A2->GND
//#define TABLE_SIZE 327680 // 5 devices: A0->GND, A1->GND, A2->+5V
//#define TABLE_SIZE 393216 // 6 devices: A0->+5V, A1->GND, A2->+5V
//#define TABLE_SIZE 458752 // 7 devices: A0->GND, A1->+5V, A2->+5V
//#define TABLE_SIZE 524288 // 8 devices: A0->+5V, A1->+5V, A2->+5V

// default to the smallest - 1 device
#ifndef TABLE_SIZE
#define TABLE_SIZE 65536

// The number of demo records that should be created. This should be less
// than (TABLE_SIZE - sizeof(EDB_Header)) / sizeof(LogEvent). If it is higher,
// operations will return EDB_OUT_OF_RANGE for all records outside the usable range.

// Arbitrary record definition for this table.
// This should be modified to reflect your record needs.
struct LogEvent {
int Lat1;
int Lat2;
int Lon1;
int Lon2;
unsigned int UTC_Time;

// Create an EDB object with the appropriate write and read handlers
EDB db(&E24C1024::write, &E24C1024::read);

// Run the demo
void setup()
Serial.println("Extended Database Library + 24XX512 EEPROM Demo");


// create a table with starting address 0
Serial.print("Creating table...");
db.create(0, TABLE_SIZE, (unsigned int)sizeof(logEvent));


for(int j = 0; j < 66; j++)

// createRecords(RECORDS_TO_CREATE);
// countRecords();
// selectAll();
// countRecords();
// deleteAll();
// countRecords();

void loop()

void recordLimit()
Serial.print("Record Limit: ");

void deleteAll()
Serial.print("Truncating table...");

void countRecords()
Serial.print("Record Count: ");

void createRecords(int num_recs)
Serial.print("Creating Records...");
for (int recno = 1; recno <= num_recs; recno++)
logEvent.Lat1 = random(1001, 1100);
logEvent.Lat2 = random(1101, 1200);
logEvent.Lon1 = random(1201, 1300);
logEvent.Lon2 = random(1301, 1400);
logEvent.UTC_Time = random(0, 240000);
EDB_Status result = db.appendRec(EDB_REC logEvent);
if (result != EDB_OK) printError(result);

void selectAll()
for (int recno = 1; recno <= db.count(); recno++)
EDB_Status result = db.readRec(recno, EDB_REC logEvent);
if (result == EDB_OK)
Serial.print("Recno: "); Serial.print(recno);
Serial.print(" LAT: ");
Serial.print(logEvent.Lat1); Serial.print("."); Serial.print(logEvent.Lat2);
Serial.print(" LON: ");
Serial.print(logEvent.Lon1); Serial.print("."); Serial.print(logEvent.Lon2);
Serial.print(" TIME: "); Serial.println(logEvent.UTC_Time);
else printError(result);

void printError(EDB_Status err)
Serial.print("ERROR: ");
switch (err)
Serial.println("Recno out of range");
Serial.println("Table full");
case EDB_OK:
Serial.println("Unknown Error");

No comments:

Post a Comment