EEPROM

From ElectroDragon
Jump to navigation Jump to search

EEPROM

Common used EEPROM ICs

  • AT24C32 ~ 256

Arduino EEPROM Demo Code and Wiring

#include <Wire.h>
#define EEPROM_END 0x50
String text = "electrodragon.com";
int start = 0;
int count = 0;
void setup(){
 Wire.begin();
 Serial.begin(9600);
 Serial.println("Writing in EEPROM...");
 for (int x=start; x<text.length(); x++){
 i2c_eeprom_write(EEPROM_END, x, byte(text.charAt(x)));
 delay(5);
 }
 Serial.println("written completed!!!");
 Serial.println("");
}
void loop(){
 for (int x=start; x<text.length(); x++){
 Serial.print(i2c_eeprom_read(EEPROM_END, x));
 }
 Serial.print(" count number: ");
 Serial.println(count);
 count+=1;
 delay(1000);
}

void i2c_eeprom_write(int end_eeprom, unsigned int end_memoria, byte valor)
{
 Wire.beginTransmission(end_eeprom);
 Wire.write((int)(end_memoria >> 8));
 Wire.write((int)(end_memoria & 0xFF));
 Wire.write(valor);
 Wire.endTransmission();
}

char i2c_eeprom_read(int end_eeprom, unsigned int end_memoria)
{
 Wire.beginTransmission(end_eeprom);
 Wire.write((int)(end_memoria >> 8));
 Wire.write((int)(end_memoria & 0xFF));
 Wire.endTransmission();
 Wire.requestFrom(end_eeprom, 1);
 byte dado;
 if (Wire.available()){
 dado=Wire.read();
 }
 Wire.endTransmission();
 return dado;
}