Hello everyone,
I'm trying to get a 24C04 EEPROM to work with my Arduino, but ran into Problems instead. I never used the Wire.h aka I2C before, so I think the problem lies somewhere in the code, but let me explain my setup first:
1/PRE = Gnd
2/E1, 3/E2 = Gnd
4/VSS = Gnd
5/SDA = Analog 4 + 0.1uF (-> Gnd) + 12k? (-> VCC)
6/SDC = Analog 5 + 0.1uF (-> GND) + 12k? (-> VCC)
7/MODE = GND
8/VCC = VCC (5V);
The memories carry a built-in 4 bit, unique device identification code (1010) corresponding to the I2C bus definition. This is used together with 2 chip enable inputs (E2, E1) so that up to 4 x 4K devices may be attached to the I2C bus and selected individually.
While E1 and E2 are pulled to GND, the address should be 101000 or 0x28 in HEX.
The MODE input is available on pin 7 and may be driven dynamically. It must be at VIL or VIH for the Byte Write mode, VIH for Multibyte Write mode or VIL for Page Write mode. When unconnected, the MODE input is internally read as VIH (Multibyte Write mode).
That means, 7/MODE could be either LOW or HIGH for bytewise write mode. Mine is LOW.
Serial Clock (SCL).
The SCL input pin is used to synchronize all data in and out of the memory. A resistor can be connected from the SCL line to VCC to act as a pull up.
Serial Data (SDA).
The SDA pin is bi-directional and is used to transfer data in or out of the memory. It is an open drain output that may be wire-OR’ed with other open drain or open collector signals on the bus. A resistor must be connected from the SDA bus line to VCC to act as pull up.
Ok, I've added some Caps (0.1uF=100pF) and Pullups(12k?) as shown here:
I'm kind of sure, the Setup should be right so far. Here is a simple example Code to test. It should first write and then read one single byte:
#include <Wire.h>
const int EEPROMID = 0x28;
int byte_address=1;
byte exampleByte =0x10;
void setup(){
Serial.begin(9600);
Wire.begin();
Serial.println("writing 1 byte..");
eepWrite(byte_address, exampleByte);
Serial.println("writing finished");
Serial.println("Reading 1 byte..");
byte b = eepRead(byte_address);
Serial.print("read: ");
Serial.println(b);
}
void loop(){};
byte eepRead(int address){
byte data;
Wire.beginTransmission(EEPROMID);
Wire.write(address);
Wire.endTransmission();
Wire.requestFrom(EEPROMID, 1);
do {
data=Wire.read();
} while(Wire.available()==0);
return data;
//if(Wire.available())data=Wire.read();
//return data;
}
void eepWrite(int address, byte data){
Wire.beginTransmission(EEPROMID);
Wire.write(address);
Wire.write(data);
Wire.endTransmission();
delay(15);
}
The Problem is, I dont know if it writes a byte, but this code gets stuck with my setup when trying to read. Serial output:
writing 1 byte..
writing finished
Reading 1 byte..
and there it stucks, so I think somethings wrong with eepRead() Method. Any suggestions?
Thanks in advance,
harald
EDIT: I forgot to add the Datasheet: 24C04 pdf, 24C04 Description, 24C04 Datasheet, 24C04 view ::: ALLDATASHEET :::