#include <Wire.h>
#define eeprom 0x50 //defines the base address of the EEPROM
void setup(void){
Wire.begin();
Serial.begin(9600);
unsigned int address = 0;
Serial.println("write");
for(address = 0; address< 20; address++) {
writeEEPROM(eeprom, address, address);
delay(5);
}
for(address = 0; address< 20; address++) {
Serial.print(readEEPROM(eeprom, address), HEX);
}
}
void loop(){}
void writeEEPROM(int deviceaddress, unsigned int eeaddress, byte data ) {
Wire.beginTransmission(deviceaddress);
Wire.write((int)(eeaddress >> 8)); //writes the MSB
Wire.write((int)(eeaddress & 0xFF)); //writes the LSB
Wire.write(data);
Wire.endTransmission();
}
byte readEEPROM(int deviceaddress, unsigned int eeaddress ) {
byte rdata = 0xFF;
Wire.beginTransmission(deviceaddress);
Wire.write((int)(eeaddress >> 8)); //writes the MSB
Wire.write((int)(eeaddress & 0xFF)); //writes the LSB
Wire.endTransmission();
Wire.requestFrom(deviceaddress,1);
if (Wire.available())
rdata = Wire.read();
return rdata;
}