i hav been encountering some issues and problems with the AT24C16 eeprom :
first i connected the A0-A1-A2 pins as told for the adress on the i2c bus to ground as told
i did put the resistors for the I2C bus as told to .
the thing is , when i used the code for the i2c eeprom it always gives me the value "255" when reading wich means the eeprom doesn't function as told .
then i tried using an i2c scanning code to check for available i2c devices : it gives me this result :
found device : adress : 0x50
found device : adress : 0x51
found device : adress : 0x52
found device : adress : 0x53
found device : adress : 0x54
found device : adress : 0x55
found device : adress : 0x56
found device : adress : 0x57
while i only connected one device and the adress for this specific eeprom with my wiring of the adress pins is supposed to be "0x50" since all the adress pins are wired to ground as told .
i checked the wiring hundreds of times in the past days yet nothing seems to make it work .
besides when i flip the i2c cables it says "no i2c device found" in the scan so something is alive but not working
pleaze help me people .
The AT24C16 chip has 3 address lines (pins 1,2,3) which aren't used because it uses those addresses internally - it doesn't matter whether you wire them up or not because that chip ignores them. An I2C scanner will find all addresses from 50 to 57 because each of the corresponding blocks of memory exist within the chip. The fact the scanner finds all of them from 50 to 57 is a good sign - the chip is being seen by the I2C correctly.
So, there's probably an error in your code somewhere. Post your code, in code tags.
thank you very much sir for helping . here is my code : " it is taken from the forum " :
// this is the main code i used
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();
}
// WARNING: address is a page address, 6-bit end will wrap around
// also, data can be maximum of about 30 bytes, because the Wire library has a buffer of 32 bytes
void i2c_eeprom_write_page( int deviceaddress, unsigned int eeaddresspage, byte* data, byte length ) {
Wire.beginTransmission(deviceaddress);
Wire.send((int)(eeaddresspage >> 8)); // MSB
Wire.send((int)(eeaddresspage & 0xFF)); // LSB
byte c;
for ( c = 0; c < length; c++)
Wire.send(data[c]);
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;
}
// maybe let's not read more than 30 or 32 bytes at a time!
void i2c_eeprom_read_buffer( int deviceaddress, unsigned int eeaddress, byte *buffer, int length ) {
Wire.beginTransmission(deviceaddress);
Wire.send((int)(eeaddress >> 8)); // MSB
Wire.send((int)(eeaddress & 0xFF)); // LSB
Wire.endTransmission();
Wire.requestFrom(deviceaddress,length);
int c = 0;
for ( c = 0; c < length; c++ )
if (Wire.available()) buffer[c] = Wire.receive();
}
void setup()
{
Wire.begin();
Serial.begin(9600);
i2c_eeprom_write_byte(0x50, 2, 'A'); delay(5);
Serial.print((char) i2c_eeprom_write_page(0x50, 2));
//this always returns the caracter of the ascii value "255" not "65" like i told it to do
// which means nothing was written to it in the first place
}
void loop() { }
That code won't work for you because it is for larger EEPROMs which require that you send two address bytes after beginTransmission (note the comments MSB and LSB).
The AT24C16 only needs one address byte. It is a 2kB device and therefore needs 11 bits to address each byte. The low 8 bits of the address are sent after the beginTransmission and the high order 3 bits of the address are sent in the beginTransmission itself.
Figure 7 of the datasheet shows how those bits are encoded.
BTW. The reason you are getting 255 when trying to read the EEPROM can be caused by incorrect wiring but this will almost always cause the I2C scanner to fail to find the device and your scan did find the device. The other reason for 255 is that you did read the device correctly but the byte that you read was in its initial "erased" state. When an EEPROM is erased it doesn't change the bytes to zero, it erases them to all-ones = 255.
dude you are awsome . the thing is now : how can i send the exact adress to the eeprom using the i2c library then ? . +my system will eventuallty require more than one eeprom . i have 2 of the same kind how can i use them both and communicate with both of them with no particular adress selected . as far as i understood
// Send the device address and the top three bits of the memory address
// which is also referred to as the Page number in the datasheet
Wire.beginTransmission(deviceaddress | ((eeaddress & 0x70) >> 7));
Wire.send((int)(eeaddress & 0xFF)); // LSB
You can't address two of those on the same bus - not easily anyway. You'd be better off getting a larger EEPROM.
well i wanna give you a bucket load of them but i seem to only be able to give one per hour . i gave you 4 already oh and can i hav an adress or something to contact you later if i need something ?