Alternate for EEPROM library


(Daniel kirubakaran) #1

I would like to start a drone project. I have analysed some sample arduino uno based drone projects , they have used EEPROM.h library and Wire.h lib as well. Since Westerndigital has provided i2c library,i am ok with that. Now,is there any alternative solution for this EEPROM library ? Which is not available for Hifive1.

Thank you.


(Wladimir van der Laan) #2

On the HiFive1 it’s possible to write to the SPI flash from the device itself. This is more or less equivalent to an EEPROM, I think? I don’t know of any example code for this, though.


(Daniel kirubakaran) #3

I will search for it.
Thank you.


(Wladimir van der Laan) #4

@mhamrick mentions having done it here:

Don’t know if there’s source available, but that thread might give some more information.


(Daniel kirubakaran) #5

I just bought a 24LC512 chip and tried with SlowSoftWire library.
It worked !!

code:
#include <SlowSoftWire.h>

SlowSoftWire Wire = SlowSoftWire(2, 3);

#define EEPROM_I2C_ADDRESS 0x50

void setup()
{
Serial.begin(57600);
Wire.begin();
Wire.setClock(400000L);
delay(250);

int address1 = 0;
byte val = 110;
int address2 = 1;
byte val2 = 25;

writeAddress(address1, val);
byte readVal = readAddress(address1);

writeAddress(address2, val2);
byte readVal2 = readAddress(address2);

Serial.print("The returned value1 is ");
Serial.println(readVal);
Serial.println("The returned value2 is ");
Serial.println(readVal2);

}

void loop()
{

}

void writeAddress(int address, byte val)
{
Wire.beginTransmission(EEPROM_I2C_ADDRESS);
Wire.write((int)(address >> 8)); // MSB
Wire.write((int)(address & 0xFF)); // LSB

Wire.write(val);
Wire.endTransmission();

delay(5);
}

byte readAddress(int address)
{
byte rData = 0xFF;

Wire.beginTransmission(EEPROM_I2C_ADDRESS);

Wire.write((int)(address >> 8)); // MSB
Wire.write((int)(address & 0xFF)); // LSB
Wire.endTransmission();

Wire.requestFrom(EEPROM_I2C_ADDRESS, 1);

rData = Wire.read();

return rData;
}

Thank you.