1

I am trying to write data in an external EEPROM using an Arduino MEGA 2560 and 24LC256 Microchip EEPROMs. I cannot use the standard Wire library because my address is 15 bits long and my pages are 64 bytes long but the Wire library only has a 32 bytes buffer.

So I tried to download the AVR library to have a better control over what's happening but I am stuck with an issue I don't understand : the program does not see the connected EEPROM (ie. it behave the same way if it is or is not connected to the Arduino).

The thing is I know my chips/cables are working because I am able to see the EEPROM when using the 'Scan_For_I2C' program.

Anyway, I had to modify the library a bit to allow it to compile (moved all the inline functions into the .h because they were initially in the .c) but I have been able to pinpoint the issue at this function call :

//! Send an I2C start condition in Master mode
inline void i2cSendStart(void)
{
    // send start condition
    outb(TWCR, (inb(TWCR)&TWCR_CMD_MASK)|BV(TWINT)|BV(TWSTA));
    TWCR &= ~(1<<TWSTA);
}

Where :

#ifndef inb
#define inb(addr)           (addr)
#endif

and

#ifndef BV
#define BV(bit)         (1<<(bit))
#endif

I am able to detect the issue by calling this :

//! Get current I2c bus status from TWSR
inline u08 i2cGetStatus(void)
{
    // retrieve current i2c status from i2c TWSR
    return( inb(TWSR) );
}

For a full detail of the code I wrote, the library used, the wiring of the EEPROM and the datasheet of the chip, download the archive on Mediafire, with this link

Thanks to anyone who might help


EDIT : I found the scan for I2C code here.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Syntaxeror
  • 11
  • 4
  • You could mention where you got that 'Scan_For_I2C' and the library from. Guessing wildly now: Did you try enabling global interrupt enable? Did you check what frequency the two programs use on SCL, maybe lib tries it faster than your device can talk or pull-ups are too high for the speed? Did you check SCL/SDA with a scope? – Stefan Bormann Mar 30 '20 at 13:59
  • I was able to check for the cables and one of them is dead, so I have to change it. But quarantine fun, it will take me time. Otherwise I added the link for the 12C scanner in the post. The frequency should be OK since both communicate on 400kHz. I'll keep you informed on the progress – Syntaxeror Apr 02 '20 at 14:09

0 Answers0