write and read EEPROM 24C64A

Hello
I am using an EEPROM chip called 24C64A.
Datasheet = https://datasheetspdf.com/pdf-file/1047305/FremontMicroDevices/24C64A/1

I need some help as I am not sure what I am doing wrong. Pin A0, A1, A2 are not connected to anything so the address is 0x50. Pin Wp is also not connected to anything so write protection is disabled. Everything else is connected correctly.

I have added the code below, as per the datasheet figure 3 I am meant to receive an ACK back after the MSB, LSB and data but what I get back is “-1” which I think means I am not getting anything back. I also write a value of 100 to address 0 but when I read it back I get 255 back. I have been through the datasheet and as far as I understand this code is correct. There is a current address read operation mentioned in the datasheet and it looks like it will read the last address that was written to so I tried following readEEPROM code:

void writeEEPROM(int deviceaddress, unsigned int eeaddress, byte data ) 
{
 Wire.beginTransmission(deviceaddress);
  Wire.endTransmission();
 
  Wire.requestFrom(deviceaddress,1);
 
  if (Wire.available()) rdata = Wire.read();
 
  return rdata;
}

It still returns 255. What have I done wrong? Any help would be appreciated. Thank you.

#include <Wire.h>    
 
#define disk1 0x50    
 
void setup(void)
{
  Serial.begin(9600);
  Wire.begin();  
 
  unsigned int address = 0;
  delay(4000);
  writeEEPROM(disk1, address, 100);
  delay(4000);
  Serial.println(readEEPROM(disk1, address));
}
 
void loop(){}
 
void writeEEPROM(int deviceaddress, unsigned int eeaddress, byte data ) 
{
  Wire.beginTransmission(deviceaddress);
  Wire.write((int)(eeaddress >> 8));   // MSB
  Serial.println(Wire.read());
  Wire.write((int)(eeaddress & 0xFF)); // LSB
  Serial.println(Wire.read());
  Wire.write(data);
  Serial.println(Wire.read());
  Wire.endTransmission();
 
  delay(5);
}
 
byte readEEPROM(int deviceaddress, unsigned int eeaddress ) 
{
  byte rdata = 0xFF;
 
  Wire.beginTransmission(deviceaddress);
  Wire.write((int)(eeaddress >> 8));   // MSB
  Wire.write((int)(eeaddress & 0xFF)); // LSB
  Wire.endTransmission();
 
  Wire.requestFrom(deviceaddress,1);
 
  if (Wire.available()) rdata = Wire.read();
 
  return rdata;
}

Pin A0, A1, A2 are not connected to anything so

they are floating?

Essentially yes I think they are floating as nothing is connected to them but I verified the address by trying other addresses and 0x50 works so the chip is configured correctly I am assuming.

And what has this got to do with Covid-19?

Have you fixed the floating thing?

I am sorry I thought I have posted this in the storage forums. Can a mod move my post please?

I will try to connect the pins physically to ground and try again.

I do not believe that the issue is the state of the address pins. The data sheet is clear on the point "If left unconnected, they are internally recognized as Vil". They are treated as 0.

I believe that you misunderstand the Wire.h library and the attempt to read an ACK or NACK with Wire.read() is not valid because no data is actually sent to the device until Wire.endTransmission() is called.

See the library code posted in this thread

Remove all the wire.read() statements from the sending function, and see if the data is correctly sent.

void writeEEPROM(int deviceaddress, unsigned int eeaddress, byte data )
{
  Wire.beginTransmission(deviceaddress);
  Wire.write((int)(eeaddress >> 8));   // MSB
 // Serial.println(Wire.read());
  Wire.write((int)(eeaddress & 0xFF)); // LSB
  //Serial.println(Wire.read());
  Wire.write(data);
  //Serial.println(Wire.read());
  Wire.endTransmission();
 
  delay(5);
}

You can certainly check the return values of Wire.endTransmission()

Returns
byte, which indicates the status of the transmission:

0:success
1:data too long to fit in transmit buffer
2:received NACK on transmit of address
3:received NACK on transmit of data
4:other error

https://www.arduino.cc/en/Reference/WireEndTransmission