Go Down

Topic: i2c 24LC256 EEPROM Library - which one ? (Read 1 time) previous topic - next topic

craigcurtin

Guys,

Trying to find the correct library to work in 1.04 with I2C EEPROM.

I have done a heap of searching but most of the libraries seem to be for the pre 1.0 environment and i am too much of a NOOB to know how to convert.

Does anyone have a known working Library for 1.04 that i can get pointed to please

(Any examples for a NOOb would also be much apppreciated)

Craig

craigcurtin

Guys,

OK i found this code which does not need an external library (other than i2c) and seems to work well.

Note it only handles single byte reads and writes - and does not implement the page write feature

Code: [Select]
#include <Wire.h>   

#define disk1 0x50    //Address of 24LC256 eeprom chip

void setup(void)
{
  Serial.begin(9600);
  Wire.begin(); 

  unsigned int address = 0;

  writeEEPROM(disk1, address, 123);
  Serial.print(readEEPROM(disk1, address), DEC);
}

void loop(){}

void writeEEPROM(int deviceaddress, unsigned int eeaddress, byte data )
{
  Wire.beginTransmission(deviceaddress);
  Wire.write((int)(eeaddress >> 8));   // MSB
  Wire.write((int)(eeaddress & 0xFF)); // LSB
  Wire.write(data);
  Wire.endTransmission();

  delay(5);
}

byte readEEPROM(int deviceaddress, unsigned int eeaddress )
{
  byte rdata = 0xFF;

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

  Wire.requestFrom(deviceaddress,1);

  if (Wire.available()) rdata = Wire.read();

  return rdata;
}

robtillaart


have a look at this - http://playground.arduino.cc/Main/LibraryForI2CEEPROM -

Not tested with 1.0.4 so please do, if it not works let it know
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

craigcurtin



have a look at this - http://playground.arduino.cc/Main/LibraryForI2CEEPROM -

Not tested with 1.0.4 so please do, if it not works let it know


Thanks for the link - tried this one earlier and it does not work.

It uses the old send and receive methods rather than write and read.

I attempted to change those instances but then other errors were thrown up and it started getting too complex for me as a NOOB.

regards

Craig

craigcurtin




have a look at this - http://playground.arduino.cc/Main/LibraryForI2CEEPROM -

Not tested with 1.0.4 so please do, if it not works let it know


Thanks for the link - tried this one earlier and it does not work.

It uses the old send and receive methods rather than write and read.

I attempted to change those instances but then other errors were thrown up and it started getting too complex for me as a NOOB.

regards

Craig



Actually i have resolved this now - but do not feel qualified to upload the results

1) the delay function was unknown - i remember reading about this somewhere so i did an include of the arduino.h in the header file - anyone know why this happens ?
2) You were using the Wiring.h library - i changed this to Wire.h and everything seems to work.

I have not checked what the example is meant to do (line by line) - but i definitely get sensible looking results on my terminal.

I think these changes need to be made to the download code to bring it in line with 1.x environment - but being a NOOB do not want to fiddle with it

Craig

robtillaart

Quote
Actually i have resolved this now - but do not feel qualified to upload the results

You can PM me the code in a zip if you want, then I will refactor it if needed and make an update on the playground.
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

robtillaart

Thanks Craigcurtin,

Merged your code with the latest existing and updated the playground article with latest version - http://playground.arduino.cc//Main/LibraryForI2CEEPROM -
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy