Read and Write on External EEPROM

Hello friends, I'm trying to do a simple routine to read and write in an EEPROM 24LC512 I / P but always the value read is: 255 I already changed memory but I got the same result. The code I am using is this below:

include "Wire.h"

define EEPROM_I2C_ADDRESS 0x50

void setup() { Wire.begin(); Serial.begin(9600);

int address = 0; byte val = 110;

writeAddress(address, val); byte readVal = readAddress(address);

Serial.print("The returned value is "); Serial.println(readVal);

delay(10000);

}

void loop() { int address = 0; byte val = 110;

writeAddress(address, val); byte readVal = readAddress(address);

Serial.print("The returned value is "); Serial.println(readVal);

delay(1000); }

void writeAddress(int address, byte val) { Wire.beginTransmission(EEPROM_I2C_ADDRESS); Wire.write((int)(address >> 8 )); // MSB Wire.write((int)(address & 0xFF)); // LSB

Wire.write(val); Wire.endTransmission();

delay(5); }

byte readAddress(int address) { byte rData = 0xFF;

Wire.beginTransmission(EEPROM_I2C_ADDRESS);

Wire.write((int)(address >> 8 )); // MSB Wire.write((int)(address & 0xFF)); // LSB Wire.endTransmission();

Wire.requestFrom(EEPROM_I2C_ADDRESS, 1);

rData = Wire.read();

return rData; }

The output is always: The returned value is 255

Help Please! Thank you!

I have tested your code and find no problem with it writing and reading a value.

I think you have a problem with the connections to the eeprom.

Does this i2c address scanner see the eeprom at address 0x50? If not, you will need to figure out whether the issue is 5v, gnd , sda or scl

// I2C Scanner
// Written by Nick Gammon
// Date: 20th April 2011

#include <Wire.h>

void setup() {
  Serial.begin (115200);

  // Leonardo: wait for serial port to connect
  while (!Serial) 
    {
    }

  Serial.println ();
  Serial.println ("I2C scanner. Scanning ...");
  byte count = 0;
  
  Wire.begin();
  for (byte i = 8; i < 120; i++)
  {
    Wire.beginTransmission (i);
    if (Wire.endTransmission () == 0)
      {
      Serial.print ("Found address: ");
      Serial.print (i, DEC);
      Serial.print (" (0x");
      Serial.print (i, HEX);
      Serial.println (")");
      count++;
      delay (1);  // maybe unneeded?
      } // end of good response
  } // end of for loop
  Serial.println ("Done.");
  Serial.print ("Found ");
  Serial.print (count, DEC);
  Serial.println (" device(s).");
}  // end of setup

void loop() {}