Show Posts
Pages: 1 [2] 3 4
16  Using Arduino / Programming Questions / Re: Why am I having so much trouble working with I2C EEPROMs? on: April 04, 2013, 02:26:06 pm
Code:
while(1) {
      Wire.beginTransmission(i2caddr);
      if(Wire.endTransmission() == 0)break;
    }

What is that doing?

Read this: http://www.gammon.com.au/i2c-summary

It's not necessary, whatever you think it is doing. Omit it.

http://www.gammon.com.au/i2c


So it's better to use a "delay(5);" instead, as it is suggested in the datasheet witch gives plenty time for byte by byte writing or page writing as we can notice on your test.
Ok
17  Using Arduino / Programming Questions / Re: Why am I having so much trouble working with I2C EEPROMs? on: April 04, 2013, 05:28:25 am

So you have a 24C02 and a 24C04.


Right, I'm quite sure of that now. Thank s for confirming the fact.


Let's start with the 24C02. Take a look at the datasheet, it has a "MODE" pin for Multibyte (4 bytes) or page select (8 bytes) to write more bytes.
But if you read and write single bytes, you don't have to use that.
It uses a single byte for the register address of 0...255.


From the datasheet link you sent me I can read §5.1.1 and §5.1.2 it is possible to write byte by byte or by pages up to 16 Bytes !
What I understand from the datasheet is that there is no difference between writting by Byte or writting by Pages till 16 Bytes. What makes the difference is whether or not, the master send the Stop condition after the ACK condition of the last Data (see figure 5 on datasheet)

For instance :
 if the Byte address is 0000 0000, I can write up to 16 Bytes of data. Data1 will be written at block address 0000 0000, Data2 at block address 0000 0001......Data 16 at block address 0000 1111. Must end with the Stop condition after the last ACK condition.

If the Byte address is 0000 0100, I can write up to only 12 Bytes of data. Data1 will be written at block address 0000 0100, Data2 at block address 0000 0101......Data 12 at block address 0000 1111. Must end with the Stop condition after the last ACK condition.

if the Byte address is 0000 0100, I can write up to 12 Bytes of data, but I can also write only 1 or 2 data. Data1 will be written at block address 0000 0100, Data2 at block address 0000 0101 and I end with a Stop condition.

So I don't see any "MODE" pin.
Am I right ?


I'm sorry to say, but I'm not happy with your code.
Could you show a function to read a single byte and a function to write a single byte. So I can comment on that.

You don't have to feel sorry, just say it. I'm beginner and am ready to ear all kind of constructive criticism.
As I said somewhere, I'm new at coding and have specific difficulties with the I2C library to understand what I'm doing. In fact till now, I've been copying piece of code found in different places.


The 24C04 has twice the memory. You can read the datasheet how they did that.
The register address is still with a single byte, but the I2C device address selects the missing address bit.
It's a dirty trick, it seems as if there are two I2C devices, each with 256 byte.

24C04, http://www.st.com/web/catalog/mmc/FM76/CL1276/SC112/PF63770


Sorry I didn't find anything concerning how "they did that"
18  Using Arduino / Storage / Re: How to read 24Cxx I2C Eprom bigger than 2Kb (ie 4kb) on: April 04, 2013, 03:17:54 am
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...
19  Using Arduino / Storage / Re: How to read 24Cxx I2C Eprom bigger than 2Kb (ie 4kb) on: April 03, 2013, 04:23:12 pm
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.
20  Using Arduino / Storage / How to read 24Cxx I2C Eprom bigger than 2Kb (ie 4kb) on: April 03, 2013, 05:08:38 am
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 ?
21  Using Arduino / Programming Questions / Re: Why am I having so much trouble working with I2C EEPROMs? on: April 02, 2013, 03:29:59 am
Hello Nick.

Unfortunately, the Smiley faces disappeared when I modified the quote tag to code tags.

Concerning this part of code :

Code:
while(1) {
      Wire.beginTransmission(i2caddr);
      if(Wire.endTransmission() == 0)break;
    }

It is (I think) to be sure "the job has been done". Before, I used a Delay(), but as I had problem, somebody told me to use this code instead. The problem I was facing was not from here, but I thought it clever to check if the job was done instead of waiting a certain amount of time between each writing.

AWOL, I don't understand what you mean. Sorry.

22  Using Arduino / Programming Questions / Re: Why am I having so much trouble working with I2C EEPROMs? on: April 02, 2013, 02:33:18 am
Ok, so I put back the 5kOhm  pull up resistor and now it still works fine.
I don't know what I've done, maybe using a wrong piece of code.

The Eeprom's reference I'm using are hard to read.

I've one :
ST CHN  F
24C02 6
K0C828

I can write and read  till 256 value in it. If I write, then read more than 256 value, the #256 store the same value as #0 and so on.

The second one I'm using is :
24C04
BL116
But the reference is very hard to see, so there might be something after the 4.
It behaves the same way as the first one despite it should be double size in memory !!!!

Here is the code I'm using :
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<258; i++)
  {
    writeData(i,i);
  }
  Serial.println("DONE");
  Serial.println("Reading data...");
  for (int i=0; i<258; 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()
{
}

Both Eeprom work the same with this code.
If I change the code to this, (concerning the way of addressing) I've got only 255 in all the bytes.

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<258; i++)
  {
    writeData(i,i);
  }
  Serial.println("DONE");
  Serial.println("Reading data...");
  for (int i=0; i<258; 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()
{
}
23  Using Arduino / Programming Questions / Re: Why am I having so much trouble working with I2C EEPROMs? on: April 01, 2013, 01:49:32 pm
Quote
don't confuse the I2C eeprom with the
eeprom inside the Arduino chips
i'm really talking about external I2C Eeprom.

Quote
Also, for external I2C eeprom, you need to use
pullup resistors.

I was having trouble with external pull up resistor, so I took them off and now it seems to work fine  without ! I thought the code of the wire.h library configured the Arduino's internal pull up resistor ! But in any case, now I'm thinking, even whether I put external pull up resistor, it should not disturb it ! The problem is that I've been doing so many manipulation and trying so many code without really understanding what I was doing, I'm making a real mess !

The link that made me thinking I may not need the external pull up resistor is :
http://playground.arduino.cc/Code/I2CEEPROM

I'm using a 24C02_6. I think the 5 of 256 is missing. So it must be a 24C0256.
I'm also using a 24C0.. unreadeable value but I can write from 0 to 255, 256 is otherwriten with the first value so I guess it's a 24C0256 also.

The project is to copy the data from an Eeprom to a new one.

If I got my code working for writing and reading now, I don't know how to do this.
Now I stored the good Eeprom's data in a Excel spreadsheet but have no idea how to program the new chip.



24  Using Arduino / Storage / Re: Problem writting I2C 24Cxx Eeprom on: April 01, 2013, 12:04:05 pm
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
25  Using Arduino / Programming Questions / Why am I having so much trouble working with I2C EEPROMs? on: April 01, 2013, 11:20:02 am
Hi.

I'm a beginer with Arduino and coding.
Till now, I've done some small thing copying and modifying some part of code from different place.
I moreless understood what I was doing and at least, acting this way I was learning.

But now I want to work with I2C EEPROM, I'm facing so many trouble !
I wonder why ? I already used library for LCD and it was quite easy and evident.

But for the EEPROM, I'm stuck, stuck, stuck !
I'm trying to read example but no way it becomes clear to me. There is always a lack of comment to me.


I was given this link to help :
http://playground.arduino.cc/Main/LibraryForI2CEEPROM

So I understand that we can write or read Byte by Byte or also with big bunch of data like "page" or maybe bit by bit if needed.
All of this is surely very interesting but doesn't unstuck me.
I think the coding comment are way to light for me.
There is a too big step with my coding experience and using the wire.h library.

I feel so sorry already asking so much help on the forum, but the situation makes me depressed.
I don't want to give up with my project.
I don't even know precisely what to ask for help. On top of that, I'm facing problem writing (eratic writing) to the Eeprom, so it doesn't help to progress !

Moderator edit: thread title toned down.
26  Using Arduino / Storage / Re: Problem writting I2C 24Cxx Eeprom on: April 01, 2013, 04:07:48 am
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.
27  Using Arduino / Storage / Problem writting I2C 24Cxx Eeprom on: March 29, 2013, 12:33:33 pm
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.
28  Using Arduino / Storage / Re: Problem for reading and writting I2C Eeprom 24c02 6 on: March 14, 2013, 07:51:49 am
Hi.

Sorry for the late response but I was on something else these time.

To make it working, I needed to power up the Arduino  through an external 12VDC power supply instead of the USB cable from the computer or even a 5vDC supply through Vin of the ARDUINO.

I also replace the delay by El Supremo's piece of code witch I thing is much more clever than wasting time with Delay and being not sure that the job is done !

But the problem was raelly the power supply of the ARDUINO. At least it now works fine.

Now I'm sure the writing and reading is ok, how can I write the proper number in each piece of memory ?

See, I've read the Eeprom I want to copy so I stored all the data in an open office format as .ods (OoCalc)or .odt (OoWriter) format)
1/   Read the data
2/   Copy from the SerialMonitor
3/   Paste in a calc or writer page to save the data in a safe place.

But I don't know how to program the new Eeprom with these data.
I'm not going to write each data at a time in the serial monitor. here must be a better way for sure.

Any advice.

How I can put these data in ?
29  Using Arduino / Installation & Troubleshooting / Re: How to find back my threads or the threads I've been answerring ? on: March 13, 2013, 07:42:41 pm
OK Nick, I've got this already.

I wanted to find back my threads even when there is no reply done.

So I got it trough my "Profile"...

Many thks
30  Using Arduino / Installation & Troubleshooting / How to find back my threads or the threads I've been answerring ? on: March 13, 2013, 08:16:01 am
Well, here is my present problem.

How to find back my threads or the threads I've been answering ?

I always have hard time to find back the threads I've posted.
Is there an easy way to do it ?
Pages: 1 [2] 3 4