Logging data to EEPROM

I am trying to log data from a thermistor to a 512-kilobit SPI EEPROM.

The project entails logging up to 65,536 thermistor samples (hence the 512kb EEPROM), then dumping the contents of the EEPROM to serial when the Arduino is next powered on. After dumping the samples, the EEPROM should be clearable by serial input from the computer. I hope that makes sense.

At the moment, I am trying to test it with millis() instead of a thermistor reading; I have come up with the following noobish code from various Arduino tutorials.

#define DATAOUT 11//MOSI
#define DATAIN 12//MISO
#define SPICLOCK 13//sck
#define SLAVESELECT 10//ss

#define WREN 6
#define WRDI 4
#define RDSR 5
#define WRSR 1
#define READ 3
#define WRITE 2

byte eeprom_output_data;
byte eeprom_input_data=0;
byte clr;
int address=0;
int numset=0;
int buffernum=0;
//data buffer
char buffer [512][128];

char spi_transfer(volatile char data)
SPDR = data; // Start the transmission
while (!(SPSR & (1<<SPIF))) // Wait the end of the transmission
return SPDR; // return the received byte

byte read_eeprom(int EEPROM_address)
int data;
spi_transfer(READ); //transmit read opcode
spi_transfer((char)(EEPROM_address>>8)); //send MSByte address first
spi_transfer((char)(EEPROM_address)); //send LSByte address
data = spi_transfer(0xFF); //get data byte
digitalWrite(SLAVESELECT,HIGH); //release chip, signal end transfer
return data;

void update_buffer(buffernum) {
for (int I=0;I<numset;I++)

  • }*
  • buffer[buffernum][numset]=millis();*
  • numset++;*
    void setup() {
  • pinMode(DATAOUT, OUTPUT);*
  • pinMode(DATAIN, INPUT);*
  • pinMode(SPICLOCK,OUTPUT);*
  • digitalWrite(SLAVESELECT,HIGH); //disable device*
    _ Serial.begin(9600);_
  • for (int A=0;A<512;I++) {*
  • update_buffer(A);*
  • for (int I=0;I<128;I++)*
  • {*
    _ Serial.print(buffer[A]); //write data byte_
    * }*
    * }*
    void loop() {
    _ if (Serial.available()) {
    * // wait a bit for the entire message to arrive*
    * delay(100);*
    * // clear the EEPROM*
    * for (int A=0;A<512;I++) {*
    * for (int I=0;I<128;I++)*
    * {*
    * spi_transfer(""); //write data byte*
    * }*
    * }*
    * }*
    * // SPCR = 01010000*
    * //interrupt disabled,spi enabled,msb 1st,master,clk low when idle,*
    * //sample on leading edge of clk,system clock/4 rate (fastest)*
    * SPCR = (1<<SPE)|(1<<MSTR);*
    * clr=SPSR;*
    * clr=SPDR;*
    * delay(10);*
    * //fill buffer with data*
    * for (int A=0;A<512;I++) {*
    * update_buffer();

    * //fill eeprom w/ buffer*
    * digitalWrite(SLAVESELECT,LOW);*
    * spi_transfer(WREN); //write enable*
    * digitalWrite(SLAVESELECT,HIGH);*
    * delay(10);*
    * digitalWrite(SLAVESELECT,LOW);*
    * spi_transfer(WRITE); //write instruction*
    * address=0;*
    * spi_transfer((char)(address>>8)); //send MSByte address first*
    * spi_transfer((char)(address)); //send LSByte address*
    * for (int A=0;A<512;I++) {*
    * for (int I=0;I<128;I++)*
    * {*
    spi_transfer(buffer[A]); //write data byte
    * }*
    * }*
    * digitalWrite(SLAVESELECT,HIGH); //release chip*
    * delay(1000);*
    However, this gives me the error:
    > variable or field ‘update_buffer’ declared void
    , and I don’t know what that means.
    I’m sure I’m missing something fairly obvious with the language or SPI/EEPROM interface. This is the first time that I’ve tried using an EEPROM, besides the example code at the SPIEEPROM tutorial. Any ideas as to how I can approach this?

When you’ve fixed that one, you need to look at the declaration of “buffer”.
I’m not sure where the 64kB of RAM comes from.

 for (int A=0;A<512;I++) { update_buffer(); }

Interesting loop construction too.

When you’ve fixed that one, you need to look at the declaration of “buffer”.

How would you recommend approaching that buffer? I’ve been unable to get anything of that magnitude to work.

I’m also not sure what the problem with void update_buffer(buffernum) is, as update_buffer() does not return anything.

I’m not sure where the 64kB of RAM comes from.

It is a 512kb EEPROM, and 512kb = 64kB.

 for (int A=0;A<512;I++) { update_buffer(); }

Interesting loop construction too.

Whoops, A should be passed to update_buffer(); there. I think that part snuck in there when I was testing it with a single-dimensional buffer. I’ve updated that in my code now.

No, "buffer" is declared in RAM; the compiler knows nothing about external (or even internal) EEPROM.