I am trying to use the 24lc256 EEPROM to store data but I am having issues with it. The EEPROM keeps giving me FF, and it isn't just one EEPROM, i tested the three that I have and all of them give me the same result. The code I am using is bellow:
#include <Wire.h>
#define eeprom 0x50
void setup(void){
Wire.begin();
Serial.begin(9600);
unsigned int address = 0;
for(address = 0; address<10; address++) writeEEPROM(eeprom, address, 3);
for(address = 0; address<10; address++) {
Serial.print(readEEPROM(eeprom, address), HEX);
Serial.print(", ");
}
}
void loop(){
}
void writeEEPROM(int deviceaddress, unsigned int eeaddress, byte data ) {
Wire.beginTransmission(deviceaddress);
Wire.send((int)(eeaddress >> 8));
Wire.send((int)(eeaddress & 0xFF));
Wire.send(data);
Wire.endTransmission();
}
byte readEEPROM(int deviceaddress, unsigned int eeaddress ) {
byte rdata = 0xFF;
Wire.beginTransmission(deviceaddress);
Wire.send((int)(eeaddress >> 8));
Wire.send((int)(eeaddress & 0xFF));
Wire.endTransmission();
Wire.requestFrom(deviceaddress,1);
if (Wire.available()) rdata = Wire.receive();
return rdata;
}