Hi,
I am trying to interface BL24C02F external eeprom with arduino uno by using library wire.h
but i am unable to write or read to and from the eeprom device.
I get the value which i initially store in rdata variable in read function when i upload this code.
#include <Wire.h>
#define chipAddress 50
void setup()
{
Serial.begin(115200);
Serial.println("EEProm Data");
Wire.begin();
unsigned int cellAddress = 0;
writeTo(chipAddress, cellAddress, 10);
Serial.println("EEProm Data---");
Serial.print(readFrom(chipAddress, cellAddress), DEC);
Serial.println("EEProm Data11");
}
void loop() {}
void writeTo(int chAddress, unsigned int ceAddress, byte wData )
{
Wire.beginTransmission(chAddress);
Wire.write((int)(ceAddress >> 8)); // MSB
Wire.write((int)(ceAddress & 0xFF)); // LSB
Wire.write(wData);
Wire.endTransmission();
delay(10);
}
byte readFrom(int chAddress, unsigned int ceAddress )
{
Wire.beginTransmission(chAddress);
Wire.write((int)(ceAddress >> 8)); // MSB
Wire.write((int)(ceAddress & 0xFF)); // LSB
Wire.endTransmission();
Wire.requestFrom(chAddress, 1);
byte rData = 0;
if (Wire.available())
{
rData = Wire.read();
}
return rData;
}