Pages: [1]   Go Down
Author Topic: Problem writting I2C 24Cxx Eeprom  (Read 1378 times)
0 Members and 1 Guest are viewing this topic.
France
Offline Offline
Jr. Member
**
Karma: 0
Posts: 50
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello.

I've been trying to work with I2C  24C02 Eeprom and got trough different issues.

With some help from the forum I fixed some but I still have problem writting data in the Eeprom.
I have erratic data when using this code.

Code:
#include <Wire.h>     // for I2C
#define i2caddr 0x50    // device address
byte d=0; // data to store in or read from the EEPROM

void setup()
{
  Serial.begin(9600); // Initialize the serial line
  Wire.begin();         // wake up the I2C
 
  Serial.println("Writing data...");
  for (int i=0; i<257; i++)
  {
    writeData(i,i);
  }
  Serial.println("DONE");
  Serial.println("Reading data...");
  for (int i=0; i<257; i++)
  {
    Serial.print(i);
    Serial.print(" : ");
    d=readData(i);
    Serial.println(d, DEC);
  }
  Serial.println("DONE");

}

// writes a byte of data in memory location addr
void writeData(unsigned int addr, byte data)
{
  Wire.beginTransmission(i2caddr);
  // set the pointer position
  //Wire.write((int)(addr >> 8));
  Wire.write((int)(addr & 0xFF));
  Wire.write(data);
  Wire.endTransmission();
  while(1) {
      Wire.beginTransmission(i2caddr);
      if(Wire.endTransmission() == 0)break;
    }
}

// reads a byte of data from memory location addr
byte readData(unsigned int addr)
{
  byte result;
  Wire.beginTransmission(i2caddr);
  // set the pointer position
  //Wire.write((int)(addr >> 8));
  Wire.write((int)(addr & 0xFF));
  Wire.endTransmission(1);
  Wire.requestFrom(i2caddr,1); // get the byte of data
  result = Wire.read();
  return result;
}

void loop()
{
}

I tried many thing and made a mistake.
I put 12V to the Eeprom instead of 5V. It means the Vcc Eeprom  was 12V, but also the SDL and SDA pull up resistor !

And this way, I got the writing procedure working good !

I was lucky to not fry the Eeprom and the SDA /SCL port of my Arduino !

But why does it work with 12V and not with the 5V (Arduino fed from USB or 12V). Even with proper 5V from Arduino board or external 5V, it doesn't write the Eeprom.
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 170
Posts: 12487
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


Check this - http://playground.arduino.cc/Main/LibraryForI2CEEPROM -

not tried with the 24C02 but it might just work!
let me know so I can update the playground article.

do you have a link to the datasheet of the 24C02?
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

France
Offline Offline
Jr. Member
**
Karma: 0
Posts: 50
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

No sorry, I have no datasheet because they are bits from different places.

Some are from my toner printer chip I want to rewrite, and some other from old TV's to try and test.

I'll have a look at the link but I'm very bad in programming and understanding program.

I'll come back and say something.

Thanks.
Logged

France
Offline Offline
Jr. Member
**
Karma: 0
Posts: 50
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Well, I put some pull up resistor on SDA and SCL (5KOhm between 5V and SDA and SCL) as it was said on were I've been looking from.

But it seems that the way the code is made is using the inner Arduino's pull up resistor !
And the wiring doesn't need external pull up resistor.

When I remove them, It seems to work fine.
I'll make some new test to be sure now that I'm getting unstuck with this.

But Why, when I made the mistake to put the Eeprom under 12V, it worked ?
Am I missing something ?
A luck I didn't burned my arduino and the Eeprom.

Anybody know the internal Arduino's pull up resistor. These must have been quite hot for some time
Logged

France
Offline Offline
Jr. Member
**
Karma: 0
Posts: 50
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

As it's been said earlier, the pull-up resistor are necessary (I'm using 4-5kOhm) despite it can work without because of the Arduino's internal pull-up resistor of I think 40kOHm.
But in case of capacitive line, it would not work properly (longer line or more than 1 I2C device on the same bus)

It seems the  "EEPROM_READ" you're using is to read the Arduino's internal Eeprom.

To read I2C Eeprom, you must use the wire.h library.

The pin 7 (WC) must be HIGH only if you want to be sure not to overwrite the Eeprom by mistake.
I usually put pin 1, 2, 3, 4, and 7 to ground to not let them floating (in case)
Logged

Pages: [1]   Go Up
Jump to: