I only get garbage out of my external EEPROM. I don’t think I’m writing garbage in, but I always get garbage out - further outputs are different depending of i2c speed…
My own conclusion is that either writing or reading or both are erroneous.
Can you see where I am wrong?
Any hint is much appreciated.
Thanks
uC: NodeMCU8266
EEPROM: FT24C256A
4k7 pullup on both lines to the EEPROM
I2C device found at address 0x50 ! using i2c scanner
Code for UNO taken from:
Modified for NodeMCU8266
Output
Write 77777 to the EEPROM -> 326323732
Write 77777 to the EEPROM -> 326323732
Write 77777 to the EEPROM -> 326323732
Write 77777 to the EEPROM -> 326323732
means garbage
Code
// Write and Read data to/from an external EEPROM
// My uC: NodeMCU8266
// My EEPROM: FT24C256A
/* EEPROM powered by 8266's 3.3V - 3.2v on the chip
Write 77777 to the EEPROM
Read results in this output 326323732 HEX - garbage!
2 different EEPROMs and 8266's are tested with similar results
100nF cer. cap directly from VCC to GND on EEPROM chip
*/
/*
Scanning...
I2C device found at address 0x50 !
done
*/
#include <Wire.h>
#define eeprom 0x50 //defines the base address of the EEPROM
int mySDA = 4; // (GPIO04) / D2
int mySCL = 5; // (GPIO05) / D1
void setup() {
Wire.begin(mySDA, mySCL);
Wire.setClock(10000); // Set down to 10000 from default value
Serial.begin(9600);
}
void loop() {
delay(1000);
unsigned int address = 0;
Serial.println("Write 77777 to the EEPROM");
for (address = 0; address < 5; address++)
writeEEPROM(eeprom, address, '7');
for (address = 0; address < 5; address++) {
Serial.print(readEEPROM(eeprom, address), HEX);
}
}
//defines the writeEEPROM function
void writeEEPROM(int deviceaddress, unsigned int eeaddress, byte data ) {
Wire.beginTransmission(deviceaddress);
Wire.write((int)(eeaddress >> 8));
Wire.write((int)(eeaddress & 0xFF));
Wire.write(data);
Wire.endTransmission();
}
//defines the readEEPROM function
byte readEEPROM(int deviceaddress, unsigned int eeaddress ) {
byte rdata = 0xFF;
Wire.beginTransmission(deviceaddress);
Wire.write((int)(eeaddress >> 8));
Wire.write((int)(eeaddress & 0xFF));
Wire.endTransmission();
Wire.requestFrom(deviceaddress, 1);
if (Wire.available())
rdata = Wire.read();
return rdata;
}