Hello,
Im trying to use this code:
http://www.arduino.cc/playground/Code/I2CEEPROM
Im using the microchip 24lc256 eeprom
and use the following code in order to test it:
#include <Wire.h>
void i2c_eeprom_write_byte( int deviceaddress, unsigned int eeaddress, byte data ) {
int rdata = data;
Wire.beginTransmission(deviceaddress);
Wire.send((int)(eeaddress >> 8)); // MSB
Wire.send((int)(eeaddress & 0xFF)); // LSB
Wire.send(rdata);
Wire.endTransmission();
}
byte i2c_eeprom_read_byte( int deviceaddress, unsigned int eeaddress ) {
byte rdata = 0xFF;
Wire.beginTransmission(deviceaddress);
Wire.send((int)(eeaddress >> 8)); // MSB
Wire.send((int)(eeaddress & 0xFF)); // LSB
Wire.endTransmission();
Wire.requestFrom(deviceaddress,1);
if (Wire.available()) rdata = Wire.receive();
return rdata;
}
void setup() // run once, when the sketch starts
{
int x;
Serial.begin(9600);
Serial.print("hello\t");
i2c_eeprom_write_byte( 0x50, 1, 26 );
x = i2c_eeprom_read_byte( 0x50, 1 );
Serial.print(x);
}
void loop() // run over and over again
{
}
The problem is that instead of printing "hello 26" I get only " hello 255"
or "hello 0" for other address (other then 1)
I hocked up the eeprom like it should be,including the 1k resistor pull ups
how can i fix it?
omri
Im trying to use this code:
http://www.arduino.cc/playground/Code/I2CEEPROM
Im using the microchip 24lc256 eeprom
Well, if you look at the top of that web page you'll see that the code is not written for a 24lc256. It's not really a surprise that it doesn't work.
Try this instead: http://wulfden.org/downloads/code/arduino/I2C_EEPROM.pde
-j
Hello,
I've tryed the wulfden's sketch but the result seems a little weird... :-/
I've dubble checked how is wired the eeprom, it look as it does.
...any suggestion to help me for debug this?
ok I've found what's wrong.
As i've hooked all address pins to ground, the address is 0x50 and not 0x51.
system
September 4, 2009, 11:02am
5
Sorry if I am bringing up an old topic, the solution to the original problem was that you need a delay between writing and reading immediately... i.e. insert delay(5); after the write command... (just for future reference)
system
September 5, 2009, 3:50am
6
I have come across a new problem with my i2c memory, hopefully someone can help me with it. I have the 512Kbits version (24FC515). The address for the bits after 256 is from 0x8000 to 0xFFFF (from spec sheet: http://ww1.microchip.com/downloads/en/devicedoc/21673E.pdf ), so to try to access the memory i did this:
#include <Wire.h>
#define I2CEEP 0x50
#define ROM_size 32768
void setup(){
unsigned int ROMindex = 0;
Wire.begin();
Serial.begin(57600);
i2c_eeprom_write_byte(I2CEEP, ROMindex, 0);
delay(5);
i2c_eeprom_write_byte(I2CEEP, ROMindex+ROM_size, 100);
Serial.println(ROMindex+ROM_size, HEX);
delay(100);
Serial.println(i2c_eeprom_read_byte(I2CEEP, ROMindex), DEC);
Serial.println(i2c_eeprom_read_byte(I2CEEP, ROMindex+ROM_size), DEC);
}
void i2c_eeprom_write_byte( int deviceaddress, unsigned int eeaddress, byte data ) {
int rdata = data;
Wire.beginTransmission(deviceaddress);
Wire.send((int)(eeaddress >> 8)); // MSB
Wire.send((int)(eeaddress & 0xFF)); // LSB
Wire.send(rdata);
Wire.endTransmission();
}
byte i2c_eeprom_read_byte( int deviceaddress, unsigned int eeaddress ) {
byte rdata = 0xFF;
Wire.beginTransmission(deviceaddress);
Wire.send((int)(eeaddress >> 8)); // MSB
Wire.send((int)(eeaddress & 0xFF)); // LSB
Wire.endTransmission();
Wire.requestFrom(deviceaddress,1);
if (Wire.available()) rdata = Wire.receive();
return rdata;
}
This gives the following outputs:
8000 (address of the first byte after 256Kbits)
100
100
So the 2nd write command seems to have overwritten the value at EEPROM index 0? I don't see why the code would produce this issue, seeing as I am using unsigned int type, which is 16 bits.
If I change:
#define ROM_size 32768/2
The output is:
4000
0
100
as expected... so I am at a loss as to why that is...