Hi,
I have this EEPROM, and here is my code :
#include <Wire.h>
char c;
void setup()
{
Wire.begin();
Serial.begin(115200);
}
void loop()
{
Wire.beginTransmission(0x50);
Wire.write(0x00);
Wire.write(0x45);
Wire.endTransmission();
Wire.beginTransmission(0x50);
Wire.write(0x00);
Wire.endTransmission(false);
Wire.requestFrom(0x50,1);
if(1<=Wire.available()){
c = Wire.read();
Serial.print(c, HEX); quelle patte est activée ou pas
Serial.print(", ");
}else
Serial.println("No data");
Serial.println();
delay(200);
}
And I always get the "No data".
I know the EEPROM is working because when I scan the I2C with a simple I2CScanner I can see it at address 0x50.
What am I doing wrong ? Because this code :
#include <Wire.h>
void setup()
{
Wire.begin();
Serial.begin(115200);
}
void loop()
{
Wire.requestFrom(0x50, 2);
while(Wire.available())
{
char c = Wire.read();
Serial.print(c & 0xFF, BIN);
Serial.print(", ");
}
Serial.println();
delay(200);
}
Give some values... Also I can see the 45 I have written with the other code..
Thank you for your help.
This example:
https://forum.sparkfun.com/viewtopic.php?t=25140
Does NOT use "Wire.endTransmission(false);" when setting the read address. Try "Wire.endTransmission();" instead.
Thank you for your help !
In the example there is a delay :
delay(10); // Without a short delay, the EEPROM is still
// writing when you start to write the next block
// Feel free to experiment with the delay length
Adding a delay just after the first "Wire.endTransmission()" and removing the false from the second one did the job.
EDIT : Found this link : https://www.hobbytronics.co.uk/arduino-external-eeprom
The EEPROM location takes about 5 ms time (known as write cycle time) to get 1-byte data written into it. Your program codes do not contain the required write cycle delay it; so, no data has been actually written into location 0x00. Please, execute the following codes which are taken from your original post and slightly modified.
#include <Wire.h>
byte c;
void setup()
{
Wire.begin();
Serial.begin(115200);
Wire.beginTransmission(0x50);
Wire.write(0x00); //EEPROM location
Wire.write(0x45); //data for EEPROM location
Wire.endTransmission();
delay(5); //write cycle delay
Wire.beginTransmission(0x50);
Wire.write(0x00); // point EEPROM location
Wire.endTransmission();
Wire.requestFrom(0x50,1);
//if(1<=Wire.available()){
c = Wire.read();
Serial.print(c, HEX); // Serial Monitor should show 45 //quelle patte est activée ou pas
}
void loop()
{
}