Hi.
I'm trying to play with a I2C EPPROM 24LC02B from an old TV set, but it gives me some strange result on reading.
Here is the code I'm using to write the first byte with 0xFF if never written by my code, then read all the byte.
#include <Wire.h>
#define EEPROM_I2C_address b1010000
void setup() {
Serial.begin(9600);
if (readFromEEPROM(EEPROM_I2C_address, 1) != 0xFF) {
Serial.println("EEPROM never writen before... ");
Serial.println("Writing to EEPROM... ");
writeToEEPROM( 1, 0xFF);
}
else {Serial.println("EEPROM already initialized... ");}
Serial.println("\nStart reading... ");
for (int i = 0; i <= 31; i++)
{
Serial.print("ligne ");
Serial.print(i+1);
Serial.print("\t\t");
for (int j = 0; j <= 7; j++) {
Serial.print(readFromEEPROM(EEPROM_I2C_address, j + i * 8));
Serial.print("\t");
delay(70);
}
Serial.println();
}
}
void loop() {
// put your main code here, to run repeatedly:
}
void writeToEEPROM(byte addr, byte data) {
Wire.beginTransmission(0x50);
Wire.write(addr);
Wire.write(data);
Wire.endTransmission();
delay(5);
}
byte readFromEEPROM(byte EEPROMAddress, byte dataAddress)
{
Wire.beginTransmission(EEPROMAddress);
Wire.write(dataAddress);
Wire.endTransmission();
delay(5);
Wire.requestFrom(EEPROMAddress, 1);
if (Wire.available()) return Wire.read();
}
But it always return 10 for all bytes read. Sometimes it reads all 0 or even all 56.
One question is the address of that 24LC02B EEPROM.
The datasheetstate that the 3 pins A0, A1, A2 usually used for selecting an I2C address are unused on that particular chip.
The A0, A1 and A2 pins are not used by the 24XX02.
They may be left floating or tied to either V SS or VCC.
type or paste code here
But I can't find in the datasheet the default address the chip will be ? I don't know what address to give in my code to address the EEPROM ?
But is it the problem why my code doesn't work ?