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?
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?
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?
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.