Pages: 1 [2]   Go Down
Author Topic: Why am I having so much trouble working with I2C EEPROMs?  (Read 1682 times)
0 Members and 1 Guest are viewing this topic.
Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

If the chip in question has a time that has to elapse before you can read back the data, you need to read the datasheet and see what that recommends.
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

AWOL is telling you, you aren't going to write more than 255 into one byte, whatever system you use.
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

This is nothing to do with I2C, or EEPROM, by the way.
Logged

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

The number after the 24C02 and 24C04 can be ignored.

This one is "24C02 6", http://www.ak-modul-bus.de/stat/serielles_eeprom_24c02.html (hard to read, but it is there).
This one is "24C026", http://cmosfold.blogspot.nl/2012/06/wiki-httpsiliconpr0n.html
This one is "24C02 6", http://www.alibaba.com/product-gs/648441339/ST24C02_SERIAL_2K_256_x_8.html

So you have a 24C02 and a 24C04.

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.

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.

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.

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

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


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"
Logged

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

The MODE pin is for types with a 'w' and older types.
So your chip might have that mode pin, but I'm not sure.

I didn't look into the Mode and pages. I was hoping that reading and writing a single byte per I2C is enough for you.

The 24C04 should have 9 address bits for the register address (A0...A8).
The address byte is 8 bits (A0...A7), so where is the missing 9th bit ?
I searched the datasheet for A8, and it is in the I2C address !
That is why you have a memory at 0x50 of 256 byte, and another memory at 0x51 also of 256 byte. Both the 0x50 and the 0x51 device are in the same 24C04.
That is how they did it.
Logged

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

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
Logged

Pages: 1 [2]   Go Up
Jump to: