Mega2560 and EEPROM via I2C problem

Hi to all!

I am having problem reading/programming 24C02 EEPROM with my Mega2560.

I am using this chip in DIP package: http://www.atmel.com/Images/doc5126.pdf

I have connected pins 1,2,3,4 and 7 to GND, pin 5 to SDA20, pin 6 to SCL21 and pin 8 to VCC (+5V). I believe everything is OK with the wiring. However, I cannot get any data from it, neither can I write data to it. Here is my piece of code, could somebody check it what am I doing wrong?

#include "Wire.h" //for I2C
#define eepromAddressRead 0xA1
#define eepromAddressWrite 0xA0
byte incomingData = 0;

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

void loop() {
  Serial.println("READING");
  delay(500);
  readi2c();
  Serial.println(incomingData);
}

void readi2c() {
  Wire.beginTransmission(eepromAddressRead);
  Wire.write(0x50); //reading from address 0x50
  Wire.endTransmission();
  Wire.requestFrom(eepromAddressRead,1);
  incomingData = Wire.read();
  Serial.println(incomingData);
}

OK, solved, device address was incorrect (correct address is 0x50). The problem is, I still don't understand how it works.

Datasheet says address consists of 8 bits, first four are 1010, next three are hardwired as 000 and the last one is 1 (read mode), giving a sequence of 10100001 or 0XA1 in hex. So why doesn't address 0xA1 work for reading?

So why doesn't address 0xA1 work for reading?

Because the read and write addresses are different, and the Arduino KNOWS whether it is reading or writing. So, YOU do not set the read/write part of the address.

I see, but usually first 4 address bits of EEPROM are 0101, but in the data sheet, it says 1010 ... is this an error?

The address of a value in the EEPROM and the address OF the EEPROM are two different things.

I see, but usually first 4 address bits of EEPROM are 0101, but in the data sheet, it says 1010 ... is this an error?

No, the Wire library and the datasheet are saying the same thing in different ways.
You specify the eeprom address to the wire library as a 7-bit number - in this case 0x50. The library knows whether it is doing a read or write and shifts the address (0x50) up by one bit and appends a 1 for read and 0 for write. That way you only have to specify the address to the library.
The datasheet doesn't know which library, or even which processor, you are using and gives a bit-by-bit description of what is required to get the eeprom to respond properly.

Pete