Wire.begin() ...Now it's saving .. Thanks ..
i am trying to save the string data inside the eeprom
https://playground.arduino.cc/Code/I2CEEPROM/#`#include <Wire.h>
void i2c_eeprom_write_byte( int deviceaddress, byte eeaddress, byte data ) {
int rdata = data;
Wire.beginTransmission(deviceaddress);
//Wire.write((int)(eeaddress >> 8)); // MSB
//Wire.write((int)(eeaddress & 0xFF)); // LSB
Wire.write(eeaddress);
Wire.write(rdata);
Wire.endTransmission();
delay(5);
}
// WARNING: address is a page address, 6-bit end will wrap around
// also, data can be maximum of about 30 bytes, because the Wire library has a buffer of 32 bytes
void i2c_eeprom_write_page( int deviceaddress, byte eeaddresspage, byte* data, byte length ) {
Wire.beginTransmission(deviceaddress);
//Wire.write((int)(eeaddresspage >> 8)); // MSB
//Wire.write((int)(eeaddresspage & 0xFF)); // LSB
Wire.write(eeaddresspage);
byte c;
for ( c = 0; c < length; c++)
Wire.write(data[c]);
Wire.endTransmission();
delay(5);
}
byte i2c_eeprom_read_byte( int deviceaddress, byte eeaddress ) {
byte rdata = 0xFF;
Wire.beginTransmission(deviceaddress);
//Wire.write((int)(eeaddress >> 8)); // MSB
//Wire.write((int)(eeaddress & 0xFF)); // LSB
Wire.write(eeaddress);
Wire.endTransmission();
Wire.requestFrom(deviceaddress,1);
if (Wire.available()) rdata = Wire.read();
return rdata;
}
// maybe let's not read more than 30 or 32 bytes at a time!
void i2c_eeprom_read_buffer( int deviceaddress, byte eeaddress, byte *buffer, int length ) {
Wire.beginTransmission(deviceaddress);
//Wire.write((int)(eeaddress >> 8)); // MSB
//Wire.write((int)(eeaddress & 0xFF)); // LSB
Wire.write(eeaddress);
Wire.endTransmission();
Wire.requestFrom(deviceaddress,length);
int c = 0;
for ( c = 0; c < length; c++ )
if (Wire.available()) buffer[c] = Wire.read();
}
void setup()
{
char somedata[] = "this is data from the eeprom"; // data to write
Wire.begin(); // initialise the connection
Serial.begin(9600);
i2c_eeprom_write_page(0x50, 0, (byte *)somedata, sizeof(somedata)); // write to EEPROM
delay(100); //add a small delay
Serial.println("Memory written");
}
void loop()
{
int addr=0; //first address
byte b = i2c_eeprom_read_byte(0x50, 0); // access the first address from the memory
while (b!=0)
{
Serial.print((char)b); //print content to serial port
addr++; //increase address
b = i2c_eeprom_read_byte(0x50, addr); //access an address from the memory
}
Serial.println(" ");
delay(2000);
}`
actual print out data : this is data from the eeprom
but it's saving only half data & print half data
16:46:51.294 -> Memory written
16:46:51.294 -> m the eeprom
16:46:53.309 -> m the eeprom
16:46:55.297 -> m the eeprom
16:46:57.330 -> m the eeprom
16:46:59.307 -> m the eeprom