Go Down

Topic: I2C eeprom problems (Read 549 times) previous topic - next topic

Chimera

Nov 29, 2012, 07:58 am Last Edit: Nov 29, 2012, 08:18 am by Nick Gammon Reason: 1
Hello,

I am trying to read from an eeprom,

http://www.google.si/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&ved=0CCgQFjAA&url=http%3A%2F%2Fwww.melexis.com%2FAsset%2FDatasheet-IR-thermometer-16X4-sensor-array-MLX90620-EEPROM-DownloadLink-6088.aspx&ei=AAK3UOGGIaqR0AWTy4A4&usg=AFQjCNFBlUtGBxEViZIAWJhEoIN4wypLAA&sig2=FEQhqfYZQv7q0aaGKFNT6w

but it seems I am doing something wrong. I am using the following I2C master library

http://homepage.hispeed.ch/peterfleury/group__pfleury__ic2master.html

The code

Code: [Select]
// INCLUDES //
#include <i2cmaster.h> // i2c master library

// DEFINITIONS //
#define EEPROM_address 0xA0

// VARIABLES //
word EEPROM_data[256];

// SETUP //
void setup()
{
 Serial.begin(115200); // setup serial communication
 i2c_init(); // initialize I2C master interface
 eepromRead(); // read eeprom  
}

// LOOP //
void loop()
{
 Serial.println("EEPROM data:");
 Serial.println(EEPROM_data[0]);
 delay(1000);
}

// FUNCTIONS //
// read all from eeprom
void eepromRead()
{
 i2c_start_wait(EEPROM_address+I2C_WRITE); // set device address and write mode (0 is write)
 i2c_write(0x00); // write address  
 i2c_rep_start(EEPROM_address+I2C_READ); // set device address and read mode (1 is read)
 
 for(int i=0;i<255;i++) {
   EEPROM_data[i] = i2c_readAck(); // read one byte and request more data
 }
 i2c_stop();  // terminate data transfer and release I2C bus  
}



Can anyone advise me please? If I do not call the eepromRead(); function in setup, I can see the output on the serial monitor ("EEPROM data: 0"). But if I call the eepromRead(); function, the serial output is blank.

Thank you and best regards,
K

Moderator edit: quote tags changed to code tags (Nick Gammon)

Nick Gammon

Code: [Select]

void loop()
{
  Serial.println("EEPROM data:");
  Serial.println(EEPROM_data[0]);
  delay(1000);
}


But you are only displaying the first byte.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Nick Gammon

Why not use the Wire library? I have stuff here about accessing EEPROMs:

http://www.gammon.com.au/i2c
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Chimera

Dear Sirs,

I am a certified idiot. Had the wrong pin configuration. Everything working now.

Thank you for the answer and help.

Best regards,
K

Go Up