1. Wagner Sartori Junior
  2. spieeprom

Wiki

Clone wiki

spieeprom / Quickstart

Some considerations

You can do two things on EEPROM. read and/or write.

The library has some functions that can read/write some variable types.

Actually it has:

  • byte(1 byte = 8 bits) - byte is a unsigned char
  • byte array
  • char(1 bytes = 8 bits)
  • char array
  • long(4 bytes = 32 bits)
  • int(2 bytes = 16-bits)
  • float(4 bytes = 32 bits)

Before setup

Initialize the SPIEEPROM class specifying your EEPROM type. Type=0 is 16-bits address. Type=1 is 24-bits address. You can found how many bits is the addressing of your EEPROM on datasheet.

Setup

Include <SPI.h> and <spieeprom.h> on your sketch.

Writing

You call the function write.

Parameters:

  • address: the address you'll write
  • data: data has to be some type that is implemented by library
  • (optional) arrLength - if you send a byte or char array, you'll have to send what's the array size

Example:

byte buffer[256];
long address;

void fill_buffer()
{
  for (int i=0;i<256;i++)
  {
    buffer[i]=99;
  }
}

...
fill_buffer();
address = 0;
disk1.write(address, buffer, (sizeof(buffer)/sizeof(byte)));
...

Reading

You call the function read_DATATYPE.

Parameters:

  • address: the address you'll write

Returns:

  • the data type you specified on function name

Example:

byte a;
long address;
address = 0;
a = disk1.read_byte(address);

Updated