I2Cmaster lib hangs on i2c_start_wait

Hey everyone,

I’m trying to talk to an external EEPROM (24LC256) over i2c using i2cmaster. I got the library installed and comiling without any issues however when i try to communicate to the eeprom, the program execution hangs. Hooking it up to the scope shows it repeatedly sending the same control byte over the SDA line.

I’m not really sure what is going wrong here, i’m unfamiliar with i2c but i did read the datasheet of the eeprom and i think that control byte is correct, though maybe the read/write bit is set incorrectly. Is the acknowledge bit correct?

Also also, is the long pulse on the SCA line the start condition?

I used Wire.h initally and it did work however the read wasn’t fast enough, so i am using i2cmaster because i read it was faster but please tell me if that is wrong.

The program was copied and pasted from Peter Fleury’s example, just the byte written to eeprom has been changed to flash the pin13 LED.

Here is the scope output Capture — ImgBB

extern "C" {
  #include <i2cmaster.h>
}
 
#define eeprom_address  0x50

void setup()
{
  pinMode(13, OUTPUT);
  digitalWrite(13, HIGH);
}
 
void loop(){
  
unsigned char ret;
    i2c_init();                             // initialize I2C library
    // write 0x75 to EEPROM address 5 (Byte Write) 
    i2c_start_wait(eeprom_address+I2C_WRITE);     // set device address and write mode
    i2c_write(0x05);                        // write address = 5
    i2c_write(B00100000);                        // write value 0x75 to EEPROM
    i2c_stop();                             // set stop conditon = release bus

    // read previously written value back from EEPROM address 5 
    i2c_start_wait(eeprom_address+I2C_WRITE);     // set device address and write mode
    i2c_write(0x05);                        // write address = 5
    i2c_rep_start(eeprom_address+I2C_READ);       // set device address and read mode
    ret = i2c_readNak();                    // read one byte from EEPROM
    i2c_stop();

    PORTB ^=ret;

    delay(1000);
  }

Have you tried to use the extEEPROM library? It’s make access to the EEPROM much easier.

Part of a test sketch I wrote to test the same EEPROM you are using.

#include <extEEPROM.h>

const uint8_t eepromAddr = 0x50;

extEEPROM eeProm(kbits_256, 1, 64, eepromAddr);

void setup()
{
  uint8_t eeStatus = eeProm.begin(extEEPROM::twiClock400kHz);
  if (eeStatus) {
    Serial.print(F("EEPROM err: "));
    Serial.println(eeStatus);
    lcd1.writeLine(1, F("EEPROM err: "));
    lcd1.write(eeStatus);
    while (1);
  }
}

Then use eeProm.read and eeProm.write for read and write,

What made you decide to use the i2cmaster library ? I think it is for the wrong reasons.
Use the Arduino Wire library.