I'm confused. I have several programs to test external EEProms and now they act as if they don't get written.`
type or paste code here
`#include <Wire.h>
#define eeprom 0x50 //defines the base address of the EEPROM
void setup() {
Wire.begin(); //creates a Wire object
Serial.begin(115200);
unsigned int address = 0; //first address of the EEPROM
Serial.println("We write the zip code 22222, a zip code");
for(address = 0; address< 5; address++)
writeEEPROM(eeprom, address, '2'); // Writes 22222 to the EEPROM
for(address = 0; address< 5; address++) {
Serial.print(readEEPROM(eeprom, address), HEX);
}
}
void loop() {
/*there's nothing in the loop() function because we don't want the arduino to
repeatedly write the same thing to the EEPROM over and over.
We just want a one-time write, so the loop() function is avoided with EEPROMs.*/
}
//defines the writeEEPROM function
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();
}
//defines the readEEPROM function
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;
}
This now outputs FFFFFFFFFF Looked at it with pulseview and it looks like it's not writing. I may be wrong, but don't understand.
I've tried several 24LCxx chips. 24lc256, 24lc512, and 24lc16 with the same results. I will admit it was quite awhile ago that I previously ran this.
Hope I posted the code ok.
You can get an inexpensive Logic Analyzer from Amazon (< $20) and download free software. Use it to monitor what's really happening on the SDC / SCL lines. The software will decode the I2C protocol for you. Do you see valid I2C transactions? Do they comply with the device's specifications and protocol?
yes, I have one and tried using pulseview. I see the transactions, but syncing it not too good. I can see it addressing the write, but not sending the write data (if I am synced correctly) I should mention that I tried Drone workshop's eeprom program and it ran fine. Also this one ran fine the last time I ran it (probably about a year ago).
After sleeping on it, it hit me this morning. It's one of those simple things that's so easy to overlook when you're looking for something more complicated to be wrong.
You need to have a delay at the end of the writeEEPROM function in order for the EEPROM to actually do the write.
//defines the writeEEPROM function
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();
delay(5); // <-- allow time for EEPROM to write
}