I2C eeprom write

Hello, I am a newbie to writing any kind of external device driver, I am trying to write some basic data to an eeprom, when I look at what I am trying to write to the eeprom here, all I see is "0". Can anyone see what I am doing wrong? I would at least expect to see 10 values written.

#define LEN 10

  byte buf[LEN];
  for(byte i =0; i < LEN; ++i)
  buf[i] = i;
  byte r = dev.write(0, buf, LEN);
  Serial.print("written:");
  Serial.println(r, HEX);

This is the output...

I2C L24AA01 EEPROM test @ 0x50 ...
written:0

why is this outputting a single "0"?

Thanks

Please post complete code so we can e.g. see which library you're using.

Usually write methods return the number of bytes written, not the content. This does not explain why you would get 0 back, it should be 10 (0x0A). So it will not return the complete array if that is what you were expecting.

Which Arduino board are you using?

This is the write function

byte M24AA01::write(byte address, byte *data, byte len)
{  
  byte r = 0;
  for(byte i=0; i<len; )
  {
    Wire.beginTransmission(EEPROM_ADDR | m_addr);
    Wire.write(address + i); 
    byte l = len > 8 ? 8 : l;
    Wire.write(data+i, l);
    r |= Wire.endTransmission();
    delay(3);
    i += l;
  }
  return r;
}

No brackets to denote the for loop. Here they are.

for(byte i =0; i < LEN; ++i) {
  buf[i] = i;
  byte r = dev.write(0, buf, LEN);
  Serial.print("written:");
  Serial.println(r, HEX);
}

That is not complete code; please write a small example that uses that method. Note that we e.g. don't know what EEPROM_ADDR and m_addr are. You will also need to show the class (if it's not part of the ino file).

Please mentiion the type number of the EEPROM For example: ATMEL 24C32) onto which you wish to perform data read/write operations.

It's a Microchip 24LC01. I am basically trying to send it a very basic couple of bytes of data and trying to read it back.

24AA01/24LC01B/24FC01 1K I2C Serial EEPROM (microchip.com)

Along with your sketch, you might want to include how the eeprom is connected to the Arduino, and which Arduino you have..

Fine:
1. Get the pin diagram (Fig-1):
EEprom24LC01
Figure-1:

2. Check that your connection between EEPROM and Arduino UNOR3 agress with Fig-2. (if you have questions, you may ask.)


Figure-2:

3. Upload the following sketch to write 0x37 at Location-12 (0x0C), read it back and show on SM (Serial Monitor). (I have not moderated your snippet sketch of post #1. Please, post full sketch so that I can do the moderation.)

#include<Wire.h>
#define deviceAddress 0x50 //101 0000

void setup()
{
  Serial.begin(9600);
  Wire.begin();
  //----checking the presence of EEPROM om I2C Bus----------
  Wire.beginTransmission(deviceAddress);
  byte busStatus = Wire.endTransmission();
  if (busStatus != 0x00)
  {
    Serial.println("EEPROM is not found!");
    while (true); //wait for ever
  }
  Serial.println("EEPROM is present.");
  
  //-----data write process--------
  Wire.beginTransmission(deviceAddress);
  Wire.write(0x0C); //pointing at EEPROM locatiom 12 = 0x0C
  Wire.write(0x37);  //data for EEPROM location, 12
  Wire.endTransmission();
  delay(5); //an EEPROM location tgakes about 5 ms time to absorb a data byte
  
  //------- read after write verification----------
  Wire.beginTransmission(deviceAddress);
  Wire.write(0x0C); //pointing at EEPROM locatiom 12 = 0x0C
  Wire.requestFrom(deviceAddress, 1);  //request to read 1-byte form EEPROM
  byte y = Wire.read();
  Serial.println(y, HEX);  //SM should show: 37
}

void loop() {}

4. Press RESET button of UNO.
Check that SM shows: 37

Second time today. If you are using an Uno R3, there is no i2c on pins A4 and A5.
Try the SDA and SCL pins by the usb connector.

When you include the following lines in your sketch, the alternate functions SDA/SCL of Pins-27/28 of ATmega328P MCU (Fig-1) of the UNOR3 Board are routed to A4/A5 pins of the edge connector. (Thre is no legend like SDA/SCL on UNOR3 Board; they are shown on UNOR4 (Fig-2).)


Figure-1


Figure-2:

As long as it's working...oh wait...
Have you run the i2c scan sketch to see if it is showing up on the i2c bus?
https://playground.arduino.cc/Main/I2cScanner/

Edit: YES! Those pins in the red circle!

From the document that you linked:

Pay attention to PC4 and PC5 which show twice (A4/A5 and (SDA/SCL). Those two sets of pins are in parallel. So A4 and A5 are the I2C pins on an board with a 328P.

...and the i2c scanner sketch returns...?

Edit: No sense continuing until it shows on the scanner.

Sorry I am a bit confused, you want me to connect SCL SDA pins (I am using arduino uno) or do you want me to connect to pins A4 and A5?

By the way, I have confirmed the address of 0x50 with i2c scanner

Using standard i2c pins SCL and SDA it, sketch returns EEPROM is not found! on the serial monitor

OK. And what does your sketch return? Does it find the eeprom? Or "not found"?

Sorry my mistake, connection issue. I now get EEPROM is preseent. 7E

Look at the official Fig-1 of post #1.

As mentioned in your first post...
Not correct. The pins near D13 are a duplicate of A4, A5.
Both sets connect to the same two I2C pins of the MCU.
Leo..