Trying to write to external EEPROM at24c32a

I am trying to write a .bin using Tera Term to at24c32a 8pin EEPROM using Arduino Leonardo, i have wired SDA to A4 , and SCL to A5, 5v and GND.

When trying to read it I'm getting either FF or numbers ranging from 255 to 75.
Its not picking up the EEPROM with I2C scanner.

I have tried numerous sketches to read , verify, but im stuck.

there are libraries out there for that. Did you try any of their examples ?

Please, post your sketch.

#include <AT24Cxx.h>
#define i2c_address 0x50

/** the current address in the EEPROM (i.e. which byte we're going to write to next) **/
int address = 0;
AT24Cxx eep(i2c_address, 32); // Initialize using AT24CXX(i2c_address, size of EEPROM in KB).

void setup() {
  // initialize serial and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }
}

void loop() {
  // Check for incoming data
  if (Serial.available() > 0) {
    // Read binary data from the serial port and write to EEPROM
    while (Serial.available()) {
      int val = Serial.read();
      Serial.println(val);

      // Update the particular EEPROM cell
      eep.update(address, val);

      // Read the value back from EEPROM for verification
      int readVal = eep.read(address);

      // Check if the read value matches what was written
      if (readVal == val) {
        Serial.println("Write to EEPROM successful.");
      } else {
        Serial.println("Write to EEPROM failed.");
        // You can add additional error handling here
      }

      // Advance to the next address, when at the end restart at the beginning
      address = (address + 1) % eep.length();

      delay(100);  // Delay to prevent flooding the serial port
    }

    Serial.println("Write operation complete.");
  }
}

Please, post the output message that you receive after the execution of the sketch of post #4.

image
And it keeps going

The deviceAddress/SlaveAddress of my 24C32 is: 0x57 (1010111). I have tested the following sketch on 24C32 EEPROM located on the DS3231 RTC Module and it is working fine. (Arduino UNO)

#include<Wire.h>
byte myData[] = {0x12, 0x24, 0x45, 0x56, 0x67, 0x78, 0x89, 0x9A, 0xAB, 0xBC, 0xCD};
int eepromAddress = 0x0001;
byte recData[11];

void setup()
{
  Serial.begin(9600);
  Wire.begin();
  
  Wire.beginTransmission(0x57);
  Wire.write(highByte(eepromAddress));  //pointing beginning address of EEPROM
  Wire.write(lowByte(eepromAddress));
  Wire.write(myData, sizeof(myData));
  byte busStatus = Wire.endTransmission();
  if(busStatus !=0)
  { 
    Serial.print("EEPROM not found...!");
    while(true);
  }
  delay(5);       //write cycle delay
  //-------------------------------------------
  Wire.beginTransmission(0x57);
  Wire.write(highByte(eepromAddress));  //pointing beginning address of EEPROM
  Wire.write(lowByte(eepromAddress));
  Wire.endTransmission();
  //--------------------------------------------

  byte n = Wire.requestFrom(0x57, 11);   //reading 11 bytes data
  for (int i = 0; i < n; i++)
  {
    recData[i] = Wire.read();
    Serial.print(recData[i], HEX);
    Serial.print(' ');
  }
}

void loop()
{

}

Output:
12 24 45 56 67 78 89 9A AB BC CD

The above is a possible device address for 24C32 EEPROM deendong on the logic values of the address selection bits (A2-A0). Change the address to 0x57 and rerun your sketch. It should work. (Arduino UNO)

I have uploaded your sketch and is working. This is the output.

49
Write to EEPROM successful.
50
Write to EEPROM successful.
Write operation complete.
51
Write to EEPROM successful.
52
Write to EEPROM successful.
Write operation complete.

Those are not I2C pins on a Leonardo.

I have used Arduino UNO. Sorry for not metioning that.

Thanks for the answers, but I tried running an I2C scanner, but it's not picking up anything. I tried running your script, I tried running mine with 0x57 and it still fails .

I changed the pins to digital 2 and 3, then to upper SDA and SCL, still didn't work.

Do you have pull up resistors on SDA and SCL?

Yes, I have 4.7k resistors. I connected them like this diagram for Nano
image

Please show a picture of your wiring, close and in focus.

Are you using a stand-alone 24C32? If yes, consult data sheets and set an address for the device by the HIGH/LOW logic of the A2-A0 address lines (Fig-1).


Figure-1:

image

Where is the common GND-line?


This is my wiring diagram

Then you first need to fix the I2C communications. Check for correct and electrically continuous connections.

Can you just let the address lines float?

I was wondering the same :slight_smile:

No word about this in the datasheet, it is only mentioned that the input on those pins select the I2C address. I strongly suspect those lines must be tied to either Vcc or GND, and can not be left floating. If in doubt: never let an input float...