I2C EEPROM AT24C16

hey

i was working with AT24C32 eeprom wrote a code for that and it work pretty well,but now i am working with 24c16
when i run the same code interfacing 24c16 the code stops working.can anyone tell me where the threat is

#include <Wire.h>
int ledpin =13;

byte high = 0x00, low=0x00;
byte dataword[]={"Hello World!"};

void setup()
{
  pinMode(ledpin ,OUTPUT);
  Wire.begin();
  Serial.begin(9600);
}

void loop()
{
   digitalWrite(ledpin ,HIGH);
  for (int i=0;i<=11;i++)
 {
    Wire.beginTransmission(0x50);
    Wire.write(high);
    Wire.write(low);
    Wire.write(dataword[i]);
    Wire.endTransmission();
    delay(5);
    low++;
 }
 low=0x00;
 for (int i=0;i<=11;i++)
 {
  Wire.beginTransmission(0x50);
  Wire.write(high);
  Wire.write(low);
  Wire.endTransmission();
  Wire.requestFrom(0x50 ,1);
  char data=Wire.read();
  delay(5);
  Serial.print("DATA  ");
  Serial.print(data);
  Serial.print("  LO ADD  ");
  Serial.println(low);
  delay(100);
  low++;
 }
 digitalWrite(ledpin ,LOW);
 while(1);
}

have a great day all
thanks

I voted for the 2nd choice. Hope that helps.

any one guys please

A few things that would be helpful. Show us a datasheet. If you added Serial.prints to show that you have made it to certain areas of your code before it hangs, will help you narrow it down to where the code is stopping. Print things like "started", "section 1", "section 2", and print (i) to find the position you are in during your for loops.

Is this the correct address of the chip? We don't know without a datasheet.

Wire.beginTransmission(0x50);

To check for a valid device address I would scan all address. The following code is an adaptation of a scanning routine

#include "Wire.h"

byte start_address = 0;
byte end_address = 127;

void setup()
{
  byte rc;
  Wire.begin();

  Serial.begin(9600);
  Serial.println("\nI2C Scanner");

  Serial.print("Scanning I2C bus from ");
  Serial.print(start_address,DEC);  Serial.print(" to ");  Serial.print(end_address,DEC);
  Serial.println("...");

  for( byte addr  = start_address;
            addr <= end_address;
            addr++ ) {
      Wire.beginTransmission(addr);
      rc = Wire.endTransmission();

      if (addr<16) Serial.print("0");
      Serial.print(addr,HEX);
      if (rc==0) {
        Serial.print(" found!");
      } else {
        Serial.print(" "); Serial.print(rc); Serial.print("     ");
      }
      Serial.print( (addr%8)==7 ? "\n":" ");
  }

  Serial.println("\n-------------------------------\nPossible devices:");

  for( byte addr  = start_address;
            addr <= end_address;
            addr++ ) {
      Wire.beginTransmission(addr);
      rc = Wire.endTransmission();
      if (rc == 0) {
        Serial.print(addr,HEX); Serial.print(" = ");
        switch (addr) {
          case 0x50: Serial.println("AT24C32/AT24C64 - EEPROM"); break;
          case 0x68: Serial.println("DS1307"); break;
          default: Serial.println("Unknown"); break;
        }
      }
  }

  Serial.println("\ndone");
}

// standard Arduino loop()
void loop()
{
    // Nothing to do here, so we'll just blink the built-in LED
    digitalWrite(13,HIGH); delay(300);
    digitalWrite(13,LOW);  delay(300);
}

This should report all I2C devices

On my little board I get:

I2C Scanner
Scanning I2C bus from 0 to 127...
00 2      01 2      02 2      03 2      04 2      05 2      06 2      07 2     
08 2      09 2      0A 2      0B 2      0C 2      0D 2      0E 2      0F 2     
10 2      11 2      12 2      13 2      14 2      15 2      16 2      17 2     
18 2      19 2      1A 2      1B 2      1C 2      1D 2      1E 2      1F 2     
20 2      21 2      22 2      23 2      24 2      25 2      26 2      27 2     
28 2      29 2      2A 2      2B 2      2C 2      2D 2      2E 2      2F 2     
30 2      31 2      32 2      33 2      34 2      35 2      36 2      37 2     
38 2      39 2      3A 2      3B 2      3C 2      3D 2      3E 2      3F 2     
40 2      41 2      42 2      43 2      44 2      45 2      46 2      47 2     
48 2      49 2      4A 2      4B 2      4C 2      4D 2      4E 2      4F 2     
50 found! 51 2      52 2      53 2      54 2      55 2      56 2      57 2     
58 2      59 2      5A 2      5B 2      5C 2      5D 2      5E 2      5F 2     
60 2      61 2      62 2      63 2      64 2      65 2      66 2      67 2     
68 found! 69 2      6A 2      6B 2      6C 2      6D 2      6E 2      6F 2     
70 2      71 2      72 2      73 2      74 2      75 2      76 2      77 2     
78 2      79 2      7A 2      7B 2      7C 2      7D 2      7E 2      7F 2     

-------------------------------
Possible devices:
50 = AT24C32/AT24C64 - EEPROM
68 = DS1307

done

@RandallR
How do you have the EEPROM wired up to the Arduino? I've been trying to get a 24LC256 to respond over I2C with no luck. I tried your scanning routine and it doesn't see anything.
I have pins 1-4 to ground.
pin 5 SDA to Analog pin 4
pin 6 SCL to Analog pin 5
Pin 7 WP to ground
Pin 8 +5V to the +5V pin on the Nano.

Pete

Here is a good site with a lot of helpful tutorials.

Here is the a link for you. Tutorial: Arduino and the I2C bus – Part Two | tronixstuff.com

I found my problem. It's a bad breadboard. I've just moved the Nano and EEPROM to a brand new one and all is well.
@cyclegadget - Thanks for the interesting link.

I hope the OP can solve his problem as easily :slight_smile:

Pete

A bit late in the day, seeing that the posts are from three years ago, but I got stuck two days on the RTC before I found that the Leonardo uses not A5 and A4 but D2 and D3 for I2C communication.

So if anybody lands here with a Leonardo that does not work: here you are.