Pages: [1]   Go Down
Author Topic: external eeprom addressing  (Read 962 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 3
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 ?
« Last Edit: November 07, 2010, 03:17:52 am by Exec » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 3
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Oh.
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."
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 3
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#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
    Wire.send(TEST[0]);
    Wire.endTransmission();
    delay(10);


}

void loop()
{
  Wire.beginTransmission(ADDR[0]); // link to 24LC04
    Wire.send(BEGIN); // must act as a position pointer
    Wire.endTransmission();
    delay(10);
    Wire.requestFrom(ADDR[0], 5); // request 5 bytes from slave device 24LC04
    delay(10);
    // 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.
Logged

Pages: [1]   Go Up
Jump to: