Go Down

Topic: New SPI EEPROM Library (Read 12428 times) previous topic - next topic


Aug 29, 2011, 05:31 pm Last Edit: Aug 29, 2011, 05:37 pm by spirilis Reason: 1
Checked out the SPIEEPROM code, looks like my code went a bit further so I decided to add support for int, long, float, and double to mine.

Decided to start using bitbucket too.  Check my version out:

(I usually rename the 'spieep' dir to SPIEEP all uppercase btw, not sure how to make that happen by default)

In addition to read, write, readn, writen, read_page, write_page, I now have:

read_int, write_int, readn_int, writen_int, read_int_offset, write_int_offset, readn_int_offset and writen_int_offset
along with long, float, and double variants of all those functions.

The EEPROM "address" you supply to each of those int/long/float/double variants gets multiplied by the size of those variables, so you could for instance use the whole EEPROM as one huge array of double's, accessing each item's address by incrementing a variable one at a time (rather than having to compute byte addresses yourself).  The "offset" variants allows you to specify a origin byte-level address where the int/long/float/double address should start counting.

Or in plain code:
read_int(p) runs the underlying readn() with (byte) address = p * sizeof(int)
read_int_offset(offset, p) runs the underlying readn() with (byte) address = p * sizeof(int) + offset

Since these functions use my readn and writen functions, they can work across page boundaries without requiring any further consideration.

I haven't actually tested the int/long/float/double variants yet, just forewarning... I will do that later :)
Hope this helps!


Tested writing & reading longs last night, seems to work correctly.

Added support for the 25LC040 to my library this morning, it'll set a simple bool in the class if it sees addrwidth = 8 bits & totalsize = 512 bytes and during any reads & writes it'll test that bool before writing the instruction (and add the 9th addrbit to the instruction if the bool is true).


Tweaked/updated some things in the code; disabled testing for Deep Power Down functionality if the EEPROM in question has less than 64KB capacity (b/c all Microchip 25LC series chips below the 512Mbit model don't seem to have it), changed some variable types in the write/read functions to avoid a few bit-width gotchas.

Added pretty thorough documentation to my wiki: https://bitbucket.org/spirilis/spieep/wiki/Home


Sep 02, 2015, 01:11 am Last Edit: Sep 02, 2015, 07:36 pm by srspinho
Hi friends,

I know that this topic is a bit old, but I´m stuck in aproblem I can not fix.

Well, I Havea circuit with a GPS, an IIC sd1306 and SPI 25c128 EEPROM memory.

I would like to record my GPS positions on this eeprom, using the SPIEEPROM lib.

My simple program is like this :

Code: [Select]

#include <SPIEEP.h>
#include <SPI.h>

SPIEEP eep(32, 64, 16384); // Microchip 25C128

#define EEPROM_CSPIN 10  // Chip Select attached to pin 10

void setup() {

void loop() {
  float buf[5];
  float Aux;
  int i;

 // Just to test
  buf[1] = 12.654;
  buf[2] = 34.567;

  // Not required for EEPROM read/write, but necessary
  // to print out the buffer contents via Serial.println
  if (!eep.write_float(0, buf[1])) {
    Serial.print("Error writing the following buffer: ");
    Serial.println(buf[1], 5);

  if (!eep.write_float(32, buf[2])) {
    Serial.print("Error writing the following buffer: ");
    Serial.println(buf[2], 5);

  Aux = eep.read_float(0);
  Serial.println(Aux, 5);

  Aux = eep.read_float(32);
  Serial.println(Aux, 5);

  while(1) ;

When I run the code, I always get the same result, showing zeroes :


Did some one used the library with float numbers without problem ?

Or, do you recomend another aproach ?

Thank you very much !

Sérgio Pinheiro

Go Up