Pages: [1]   Go Down
Author Topic: How to read 24Cxx I2C Eprom bigger than 2Kb (ie 4kb)  (Read 5123 times)
0 Members and 1 Guest are viewing this topic.
France
Offline Offline
Jr. Member
**
Karma: 1
Posts: 85
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi.

I had already some problem with I2C Eeprom, but bit by bit I'm getting sorted out.

I've used Nick Gammons' I2C scanner and found my Eeprom is a 4kb, so I find 2 devices 0x50 and 0x51 on the same Eeprom.

Here is Nick Gammons' I2C scanner I've used.

Code:
// I2C Scanner
// Written by Nick Gammon
// Date: 20th April 2011

#include <Wire.h>

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

  // Leonardo: wait for serial port to connect
  while (!Serial)
    {
    }

  Serial.println ();
  Serial.println ("I2C scanner. Scanning ...");
  byte count = 0;
 
  Wire.begin();
  for (byte i = 1; i < 120; i++)
  {
    Wire.beginTransmission (i);
    if (Wire.endTransmission () == 0)
      {
      Serial.print ("Found address: ");
      Serial.print (i, DEC);
      Serial.print (" (0x");
      Serial.print (i, HEX);
      Serial.println (")");
      count++;
      delay (1);  // maybe unneeded?
      } // end of good response
  } // end of for loop
  Serial.println ("Done.");
  Serial.print ("Found ");
  Serial.print (count, DEC);
  Serial.println (" device(s).");
}  // end of setup

void loop() {}

Then, to read i'm using this :

Code:
#include <Wire.h>
 
#define disk1 0x50
 
void setup(void){
 Serial.begin(9600);
 Wire.begin();
 unsigned int address = 0;
 for (address = 0; address < 4096; address++)
 { 
 Serial.print(address);
 Serial.print("\t");
 Serial.print(readEEPROM(disk1, address), DEC);
 Serial.println();
 }
 }
 void loop()
 {
 }
 byte readEEPROM(int deviceaddress, unsigned int eeaddress )
{
 byte rdata = 0xFF;
 Wire.beginTransmission(deviceaddress);
 Wire.write((int)(eeaddress >> 8));   // MSB
 Wire.write((int)(eeaddress & 0xFF)); // LSB
 Wire.endTransmission();
 
 Wire.requestFrom(deviceaddress,1);
 
 if (Wire.available()) rdata = Wire.read();
 return rdata;
}

But I've got only 255 value in all world adress.

If I take off this part of code :
Code:
Wire.write((int)(eeaddress >> 8));   // MSB

I've can read till #255 the right value, then on #256 I'm reading back #0 value.

How can I do for correctly addressing world further than 255 ?
Logged

Offline Offline
Edison Member
*
Karma: 58
Posts: 2078
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Is it a 24C04 ?
They are 4kbit = 512 byte.

You find the first 256 bytes at I2C address 0x50 and the second 256 bytes at 0x51.
The address for the 24C04 is a single byte, not the MSB and LSB you use.

Or is it a 24C32 ?
Logged

France
Offline Offline
Jr. Member
**
Karma: 1
Posts: 85
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi.

As I can hardly read on the package and the result I get with Nick Gammon's  I2C scanner Sketch, It is a 24C04.

Why do you think it would be a 24C32 ?

But most of the time, Eeprom I2C Arduino's Sketches are done to work with address on 2 bytes like here.

http://www.hobbytronics.co.uk/arduino-external-eeprom

Is only the 24C04 that work as 2 devices 0x50 and 0x51 and address on 1 byte only ? I've only a 24c02 and a 24c04 to play with at the moment.
Logged

Offline Offline
Edison Member
*
Karma: 58
Posts: 2078
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The address is a byte, read the datasheet.
I told you two days ago, http://arduino.cc/forum/index.php/topic,157729.msg1182279.html#msg1182279
Logged

France
Offline Offline
Jr. Member
**
Karma: 1
Posts: 85
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

OK guies.

I missed some replies and I must study them before you give more information.

Many thanks to all.

I've been doing so many mistake and so giving so many wrong information in my previous post.
Hopefully you made me figuring them out but I hope it won't confuse other beginners.

In fact, I 'm using a 2kb and a 4kb Eeprom and the 4kb must be seen as 2 devices (thanks to Nicks' I2C scanner) and it needs the pull up resistor despite the Arduino has small 40kohm ones (too weak for more capacitive circuit, like long line or more than one Eeprom....I'm learning...
Logged

Norway
Offline Offline
Full Member
***
Karma: 1
Posts: 143
likes to program Arduinos!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

you can use the EEPROM24 library.
I've used it a lot and it's easy to interface with, and doesn't take a lot of space either.
you can download it here: http://rweather.github.io/arduinolibs/classEEPROM24.html
Logged

France
Offline Offline
Jr. Member
**
Karma: 1
Posts: 85
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What makes me mistaken is that I've been using 24c02 and 24C04 that are addressed on only 1byte.

You'll say, the 24C04 can't be addressed on only 1 byte. But it is ! Well not really.

In fact, the address block is on 1byte, the 24C04 is seen as 2 devices (1 on 0x50 and 1 on 0x51), the A0 pin has no function (no connect) and there is a 9th bit somewhere that I can't yet understand how it works and where it is.
This means that a 24C04 is using 2 devices addresses !

Bigger I2C Eeprom have their block address coded on 2 bytes, that mean up to 64kB on the same device I think (24C512)

The link you gave previously talks about a 24LC1025 24LC1026 of 128kB !
Twice more addresses than 2^16 (2 bytes addresses possibilities).

Is it using the same trick as for the 24C04 ?

This is quite confusing to me indeed !
Logged

Offline Offline
Edison Member
*
Karma: 58
Posts: 2078
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It is confused. You have to check for every EEPROM how to interface it.

Those 24LC1025 use the same trick. They have two bytes for the address and the missing 2 address bits are in the I2C address. So it should be on the I2C bus as being four devices.
Logged

France
Offline Offline
Jr. Member
**
Karma: 1
Posts: 85
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Would you excuse me for insisting so much, but the 24LC1025 shouldn't it be seen only as 2 devices ?

The 24LC512 is seen as 1 device. Right ?
2 bytes is 16 bits that gives 65536 possibilities for block's address.
and the 24LC512 has 512*1024/8 = 65536 block addresses. right ?

So the 24LC1025 should be seen only as 2 devices. (2 x 24LC512)

Or am I wrong.
Logged

Offline Offline
Edison Member
*
Karma: 58
Posts: 2078
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You are right.
Sorry for the confusing.
According to the datasheet, an address bit "B0" in the I2C address selects which 'half' of the memory is selected. So that is one extra address bit.
Logged

France
Offline Offline
Jr. Member
**
Karma: 1
Posts: 85
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

you can use the EEPROM24 library.
I've used it a lot and it's easy to interface with, and doesn't take a lot of space either.
you can download it here: http://rweather.github.io/arduinolibs/classEEPROM24.html

So I think this library can work only for the 1 Eeprom = 1 device Eeprom style.
No for for the 1 Eeprom = 2 devices Eeprom style.

I'm really confused about this.
Logged

Norway
Offline Offline
Full Member
***
Karma: 1
Posts: 143
likes to program Arduinos!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It have a configuration so you can run 2 (or more?) eeproms at the same i2c address, so two 24lc32 becomes one 24lc64
Logged

France
Offline Offline
Jr. Member
**
Karma: 1
Posts: 85
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It have a configuration so you can run 2 (or more?) eeproms at the same i2c address, so two 24lc32 becomes one 24lc64

Oh nooooo !

You're making things even more complicated now ! Are you sure this is possible that way ?
Logged

Norway
Offline Offline
Full Member
***
Karma: 1
Posts: 143
likes to program Arduinos!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

the link I gave you says:

" There can be multiple 24LCXX chips on the same I2C bus, as long as their A0, A1, and A2 address pins are set to different values. For example, two 24LC256 chips can be used to provide the same memory capacity as a single 24LC512 chip. The optional bank parameter to the constructor is used to assign different bank addresses to each chip:

 SoftI2C i2c(A4, A5);
 EEPROM24 eeprom0(i2c, EEPROM_24LC256, 0);
 EEPROM24 eeprom1(i2c, EEPROM_24LC256, 1);  "


this is all you need to communicate with any 24Cxxx EEPROM. Just replace the part saying "EEPROM_20LC04" with your spesifil EEPROM type. (You will have write LC instead of C, because this library was originally designed for microchip's i2c EEPROMs. However, the library should support all kinds of eeproms starting with 24.

EDIT:
Forgive me, you cant run two EEPROMS at the same address, but you can, like I mentioned, make two EEPROMS act as twice as large EEPROM


Code:
#include "EEPROM24.h"

 SoftI2C i2c(SDA, SCL); //(A4,A5);
 EEPROM24 eeprom(i2c, EEPROM_24LC04,0x50);
 
byte value;
int address = 0;

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

 void loop() {
  value = eeprom.read(address);
  
  Serial.print(address);
  Serial.print("\t");
  Serial.print(value, DEC);
  Serial.println();
  
  // advance to the next address of the EEPROM
  address = address + 1;
  
  // there are only 512 bytes of EEPROM, from 0 to 511, so if we're
  // on address 512, wrap around to address 0
  if (address == 128){
    address = 0; }
    
  delay(500);
    
 }


The download page doesn't have a dowload link, so you will have to copy the source code on the page. If you want I can upload the library for you smiley
« Last Edit: April 12, 2013, 01:51:00 am by hansibull » Logged

Sydney, Australia
Offline Offline
Sr. Member
****
Karma: 6
Posts: 397
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

the link I gave you says:

" There can be multiple 24LCXX chips on the same I2C bus, as long as their A0, A1, and A2 address pins are set to different values. For example, two 24LC256 chips can be used to provide the same memory capacity as a single 24LC512 chip. The optional bank parameter to the constructor is used to assign different bank addresses to each chip:

 SoftI2C i2c(A4, A5);
 EEPROM24 eeprom0(i2c, EEPROM_24LC256, 0);
 EEPROM24 eeprom1(i2c, EEPROM_24LC256, 1);  "


this is all you need to communicate with any 24Cxxx EEPROM. Just replace the part saying "EEPROM_20LC04" with your spesifil EEPROM type. (You will have write LC instead of C, because this library was originally designed for microchip's i2c EEPROMs. However, the library should support all kinds of eeproms starting with 24.

EDIT:
Forgive me, you cant run two EEPROMS at the same address, but you can, like I mentioned, make two EEPROMS act as twice as large EEPROM


Code:
#include "EEPROM24.h"

 SoftI2C i2c(SDA, SCL); //(A4,A5);
 EEPROM24 eeprom(i2c, EEPROM_24LC04,0x50);
 
byte value;
int address = 0;

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

 void loop() {
  value = eeprom.read(address);
  
  Serial.print(address);
  Serial.print("\t");
  Serial.print(value, DEC);
  Serial.println();
  
  // advance to the next address of the EEPROM
  address = address + 1;
  
  // there are only 512 bytes of EEPROM, from 0 to 511, so if we're
  // on address 512, wrap around to address 0
  if (address == 128){
    address = 0; }
    
  delay(500);
    
 }


The download page doesn't have a dowload link, so you will have to copy the source code on the page. If you want I can upload the library for you smiley


HI - not wanting to thread hijack but was looking for some info on how to use 24LC256 chips and found this - i have downloaded all the files you linked to but do not want to use his softi2c library - do you know how to use this code with the standard hard coded i2c ports (in my case i am on a Mega, but neither here nor there)

I am a NOOB to Arduino so little words would be relly good !! smiley-grin

I think i am having problems where they define the i2c data type for their softi2c at the start - if i could tell that to use the wire library i think i would be right (but i have no idea how to do that one

Craig



Logged

Pages: [1]   Go Up
Jump to: