24c08 /04 /02 Simple Command Lines

Working libraries, libraries being ported and related hardware
Post Reply
jdenis
Posts: 1
Joined: Sun May 08, 2016 7:18 pm

24c08 /04 /02 Simple Command Lines

Post by jdenis » Wed Aug 02, 2017 10:03 am

Hi, this is my first try of contribution so i apologize for any mistakes...

A while ago I was looking for a simple library to read/write on 24c i2c eeproms end nothing, found some very heavy ones, or ones with unused commands so since I like very simple and light programs I made and use this one, so if it helps someone I will be glad!

It's very simple and only does what is needed for config. points, ie.

Code: Select all

eeprom_read(10);
reads the 10th address of the eeprom,

Code: Select all

eeprom_write(10, 255);
writes 255 on address 10, and that's it!

I did a 15ms delay because some delay is needed if you are doing repetitive writes but i do believe its possible to shrink that but it's not to long since the i2c eeproms are very small (but good to store configuration points).

Cheers!

Code: Select all

void eeprom_write(byte eeaddress, byte data){Wire.beginTransmission(0x50); Wire.write(eeaddress); Wire.write(data); Wire.endTransmission(); delay(15);}
byte eeprom_read(int eeaddress){byte rdata = 0x00; Wire.beginTransmission(0x50); Wire.write(eeaddress); Wire.endTransmission(); Wire.requestFrom(0x50, 1); delay(1); if(Wire.available()) rdata = Wire.read(); return rdata;}

victor_pv
Posts: 1681
Joined: Mon Apr 27, 2015 12:12 pm

Re: 24c08 /04 /02 Simple Command Lines

Post by victor_pv » Wed Aug 16, 2017 5:03 pm

jdenis wrote:
Wed Aug 02, 2017 10:03 am
Hi, this is my first try of contribution so i apologize for any mistakes...

A while ago I was looking for a simple library to read/write on 24c i2c eeproms end nothing, found some very heavy ones, or ones with unused commands so since I like very simple and light programs I made and use this one, so if it helps someone I will be glad!

It's very simple and only does what is needed for config. points, ie.

Code: Select all

eeprom_read(10);
reads the 10th address of the eeprom,

Code: Select all

eeprom_write(10, 255);
writes 255 on address 10, and that's it!

I did a 15ms delay because some delay is needed if you are doing repetitive writes but i do believe its possible to shrink that but it's not to long since the i2c eeproms are very small (but good to store configuration points).

Cheers!

Code: Select all

void eeprom_write(byte eeaddress, byte data){Wire.beginTransmission(0x50); Wire.write(eeaddress); Wire.write(data); Wire.endTransmission(); delay(15);}
byte eeprom_read(int eeaddress){byte rdata = 0x00; Wire.beginTransmission(0x50); Wire.write(eeaddress); Wire.endTransmission(); Wire.requestFrom(0x50, 1); delay(1); if(Wire.available()) rdata = Wire.read(); return rdata;}
Thanks for sharing, it's definitely a very implementation, but I bet is enough for most use cases.

Post Reply