4

EDIT: I was a BIT confused about the BITS and BYTES, documention specify bits and not in bytes and read the bits as bytes. This explains my error. Why manufacturers use bits instead of bytes to specify capacity? it is a BIT confusing. ;-)


I found the Atmel 24C02n 2kb EEPROM on a spare board and want to give it a try to see what kind of data is inside this chip and if I can reuse it. Never done reading/writing external memory. The wiring is easy (i2c) and works perfectly fine.

Run the i2cScanner and it found 8 addresses on the bus, 0x50 .. 0x57. First thought: "strange, 8 addresses for one device." The documentation describes there are 8x256 bytes, so okay, 8 addresses for 8 pages of 256 bytes.

However, when I want to access the another page, for example 0x51, I get the same data and it seems to write to the same memory page. Do I miss something here?


This is my example code using the wire library:

#include <Wire.h>

int     A24C_PAGE_COUNT     = 8;
uint8_t A24C_PAGE_ADDR[8]   = { 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57 };
int     A24C_PAGE_SIZE      = 256;  

uint8_t eepromReadAddress(int address, int from_addr) 
{
  Wire.beginTransmission(address);
  Wire.write(from_addr);

  Wire.requestFrom(address, 1);

  uint8_t iResult = (Wire.available())?Wire.read():0x32;
  Wire.endTransmission();

  return iResult;
}    

void eepromWriteAddress(uint8_t address, uint8_t from_addr, uint8_t* data) 
{
  Wire.beginTransmission(address);

  Wire.write(from_addr);
  while( *data )
   { Wire.write( *data++ ); }

  Wire.endTransmission();
}

void eepromRead()
{
  int iByte = 0;
  int iPage = 0;
  while( iPage < A24C_PAGE_COUNT )
  {
    Serial.print( "PAGE: " );
    Serial.println( iPage+1 );

    while( iByte < A24C_PAGE_SIZE )
    {
      //Serial.print( "0x" );
      Serial.print( (char)eepromReadAddress( A24C_PAGE_ADDR[ iPage ], iByte ) );
      ++iByte;
      Serial.print(( iByte % 16 == 0 )?"\n":",");
    }

    iByte=0;
    ++iPage;
  } 
}

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

  delay( 1000 );
  //eepromWriteAddress( 0x50, 128, "Hello world!" );
  eepromRead();
}

void loop() {
} 

Output after once write "Hello world!" to first page at position 128, i will get:

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?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?
?,H,e,l,l,o, ,w,o,r,l,d,!,?,?,?
?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?
?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?
?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?
?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?
?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?
?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?
?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?
PAGE: 8
G, ,?,?,, ,,k, ,, ,, ,., ,
 ,, ,!,,,,?, ,,!,?, ,Q,?,4
 ,?, ,,I,?, ,<, ,?,?,?,?,?,?,?
?, ,D, ,,<, ,,?, ,, ,,t, ,
?, ,?,?,?,?,?, , , , , , , , ,
 , , , , , , , , , , , , , , ,
 , , , , , ,?,?,?,?,?,?,?,?,?,?
?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?
?,H,e,l,l,o, ,w,o,r,l,d,!,?,?,?
?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?
?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?
?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?
?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?
?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?
?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?
?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?

Each address points to the same page????

Okay, another approach, changed the following variables to read one large page (just a try to see what will happen):

int     A24C_PAGE_COUNT     = 1;
int     A24C_PAGE_SIZE      = 2048;

Same result, only first page displayed however repeated 8 times. So what do I wrong? And why are there 8 addresses for one device anyway?

Codebeat
  • 6,501
  • 6
  • 57
  • 99
  • The documentation doesn't say there's 8 x 256 **bytes**. It says there's 8 x 256 = 1024 **bits** you can store. So all is based on a false assumption and should be re-thought. – tofro Dec 15 '17 at 09:51
  • @tofro: Thanks for pointing out, and yes, I did read the specs wrong assuming it is bytes instead of bits. Anyway, 8*256 = 2048 bits and not 1024 like you just said. 256 bytes is not very useful except to store some simple configuration settings. However, still my reading function and writing function works correctly, I can read/write all of the capacity tho. But why manufacturers mention bits instead of bytes? All capacity is measured in bytes, very confusing and explains my error. – Codebeat Dec 15 '17 at 19:06

1 Answers1

1

Memory capacity of RAM and ROM is normally expressed in bits, not bytes as you seem to assume.

So this chip you are referring to has 8 x 256 bits of EEPROM and you seem to be expecting much more memory than is actually present - You can store 256 bytes in that chip.

The low-capacity chips apparently use the same address decoding mechanism than the higher-capacity chips, so what you seem to be seeing is a simple wrap-around of addresses while you are reading the same bytes over and over again (see pg. 10 of the datasheet on "roll-over").

With regards to your "answers to more than one I2C address" - How did you connect the A0, A1, A2 lines? They need to be hard-wired to create the device's address.

tofro
  • 5,640
  • 14
  • 31
  • Thanks for pointing out, and yes, I did read the specs wrong assuming it is bytes instead of bits. 256 bytes .... is not very useful except to store some simple configuration settings. However, still my reading function and writing function works correctly, I can read/write all of the capacity of the memory. But why manufacturers mention bits instead of bytes? All capacity is measured in bytes, very confusing and explains my error. – Codebeat Dec 15 '17 at 19:08
  • Yes, i connected A0...A2 to ground (LOW) so it must be on address 0x50 but shows all possible adresses on the bus. Don't know why but it doesn't matter actually because I can read and write the full capacity, the 256 bytes. – Codebeat Dec 15 '17 at 19:10
  • 1
    They do that because not all computers have 8-bit bytes and not all computers read 8-bit-wise (an ARM chip, for example, can only address 32-bit long words). For this specific chip it probably doesn't make much sense (after all, it wants to be read and written byte-wise in 8-bit chunks), but follows the same convention. – tofro Dec 15 '17 at 20:39