Go Down

Topic: external eeprom addressing (Read 2922 times) previous topic - next topic


Nov 07, 2010, 04:49 am Last Edit: Nov 07, 2010, 09:17 am by Exec Reason: 1
Hi there
Could anybody explain me addressing eeprom in I2C?
As far as I understand datasheet for my 24c04 it has following adress format:
1010 A2 A1P0 R/W
The 4K EEPROM only uses the A2 and A1 device address bits with the third bit being a memory page address bit.

So, if i connect A0,A1 and A2 to GRD, adress would be 1010 0000 for writing and 1010 0001 for reading. In HEX it would be A0h and A1h relatively.
But all examples i've seen uses 0x50 to adress eeprom, with no A 5v-powered, 0x51 for A0 powered, 0x52 for A1 powered and so on. But binary it would by 00000101 00000000, 00000101 00000001, 00000101 00000010

The question is why ?


I found my fault in WIRE library descriprion.

"There are both 7- and 8-bit versions of I2C addresses. 7 bits identify the device, and the eighth bit determines if it's being written to or read from. The Wire library uses 7 bit addresses throughout. If you have a datasheet or sample code that uses 8 bit address, you'll want to drop the low bit (i.e. shift the value one bit to the right), yielding an address between 0 and 127."


Still can't force it to work...

Code in playground doesn't work. All I've got -

ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿMemory written
ÿÿÿÿÿÿÿÿÿÿÿÿÿÿ and so on.

I test this
Code: [Select]
#include <Wire.h> // specify use of Wire.h library.

// address in 24ATC04 values from 0 to 511.

int BEGIN = 0;
int ADDR[] = {
 0x50, 0x51, 0x52, 0x53, 0x54};
char* TEST[] = {
 "Chip0", "Chip1", "Chip2", "Chip3", "Chip4"};

void setup()
 Wire.begin(); // join i2c bus (address optional for master)
 Serial.begin(9600);  // setup serial for output
 // send test message "Arduino"

   Wire.beginTransmission(ADDR[0]); // connect to 24LC04 device address
   Wire.send(BEGIN); // beginning address within EEPROM


void loop()
 Wire.beginTransmission(ADDR[0]); // link to 24LC04
   Wire.send(BEGIN); // must act as a position pointer
   Wire.requestFrom(ADDR[0], 5); // request 5 bytes from slave device 24LC04
   // below will loop until 5 bytes are received.

   while(Wire.available()) // slave may send less than requested
     char c = Wire.receive(); // receive a byte as character
     Serial.print(c); // print the character
   Serial.print("\n"); // next line
  delay(1000); // wait one second.

This code works, but it only writes and reads first 5 bytes of memory, while I need read all bytes.

How to do that? I stumbled for the third day  :-/
24c04 has 32 pages each of 16 bytes.

Go Up