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:
PAGE: 1
G, ,?,?,, ,,k, ,, ,, ,., ,
,, ,!,,,,?, ,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,?,?,?
?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?
?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?
?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?
?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?
?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?
?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?
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?