Reading from External EEPROM Arduino Due I2C

Good Morning All
i have been breaking my head over something for a couple of weeks now, and i have not had any success.
I have read multiple forum posts on here but i cannot quite find what i am looking for.
Alot of posts in German that do not translate correctly.
I saw a few items that had potential to help but did not make any difference. so i figured i would start over and ask here.
A little background on the big picture of what i am trying to do:
I am working on a project (K3NG Keyer) i don't want to waste everyone's time explaining all i am trying to do with it, but the short of it is, i need the HID interface, and the large flash memory of the DUE. but the DUE does not have any on chip EEPROM so i am trying to use I2C External EEPROM.

When running the code, i have my logic analyzer on the I2C bus and every time the EEPROM is polled for a read, the EEPROM sends back a NAK. so every time the circuit re-boots it cannot read the EEPROM and i have to re-input all my settings. This is not ideal.

There is only about 50 bytes of data that is sent to and read from the EEPROM.
it appears the DUE will write to the EEPROM. i see the write to 0X50 ACK data 0X00 0x23
and the program will cycle through all the data that needs to be written.
When the device is powered on, the DUE asks the EEPROM to check a memory for a specific number, and that read is met with a NAK so the DUE think the EEPROM has not been initialized.

i tried troubleshooting the code, but its 18000 lines. I have the issue narrowed down to two parts of the code.

The code uses
#include <AT24C1024.h>
which is the h file for the EEPROM subroutine.
The code compiles but the EEPROM does not work.

I know the I2C bus works because i have an LCD that works correctly.

i tried a couple different EEPROMS to make sure that wasn't the issue and i also powered the DUE from a DC power supply not just through the USB.

In my troubleshooting, i pulled the example file out of the AT24C1024 Library and just ran that code to see if it is something in the larger project file that is bad.

Well - i ran this code (posted below) and i get the same issue. The EEPROM only provides a NAK when read from. There is also about only one successful Write for every 4 writes.

Would anyone know why this isn't working for me? why i keep getting the NAK?
if i get this example code to work, i will see if i can incorporate it in the larger code i am trying to work with. Like i said, i didn't want to post 18k lines of code into this forum that would not be fair to anyone.

If anyone wants to see the "larger" code it is here GitHub - k3ng/k3ng_cw_keyer: K3NG Arduino CW Keyer
the lines i am having trouble with are

void write_settings_to_eeprom(int initialize_eeprom)

this sees like the subroutine in the overall code that does not work correctly.
I have asked on the forums for this project but its been a couple weeks and have not received any useful information.

Thank you all.

#include "Adafruit_EEPROM_I2C.h"

/* Example code for the Adafruit I2C EEPROM breakout */

/* Connect SCL    to SCL
   Connect SDA    to SDA
   Connect VDD    to 3 - 5V DC
   Connect GROUND to common ground */
   
Adafruit_EEPROM_I2C i2ceeprom;

#define EEPROM_ADDR 0x50  // the default address!

void setup(void) {
  Serial.begin(115200);
  
  if (i2ceeprom.begin(0x50)) {  // you can stick the new i2c addr in here, e.g. begin(0x51);
    Serial.println("Found I2C EEPROM");
  } else {
    Serial.println("I2C EEPROM not identified ... check your connections?\r\n");
    while (1) delay(10);
  }
  
  // Read the first byte
  uint8_t test = i2ceeprom.read(0x0);
  Serial.print("Restarted "); Serial.print(test); Serial.println(" times");
  // Test write ++
  test++;
  i2ceeprom.write(0x0, test);

  // Try to determine the size by writing a value and seeing if it changes the first byte
  Serial.println("Testing size!");

  uint32_t max_addr;
  for (max_addr = 1; max_addr < 0xFFFF; max_addr++) {
    if (i2ceeprom.read(max_addr) != test)
      continue; // def didnt wrap around yet

    // maybe wraped? try writing the inverse
    if (! i2ceeprom.write(max_addr, (byte)~test)) {
        Serial.print("Failed to write address 0x");
        Serial.println(max_addr, HEX);
    }

    // read address 0x0 again
    uint8_t val0 = i2ceeprom.read(0);

    // re-write the old value
    if (! i2ceeprom.write(max_addr, test)) {
        Serial.print("Failed to re-write address 0x");
        Serial.println(max_addr, HEX);
    }    

    // check if addr 0 was changed
    if (val0 == (byte)~test) {
      Serial.println("Found max address");
      break;
    }
  }
  Serial.print("This EEPROM can store ");
  Serial.print(max_addr);
  Serial.println(" bytes");
    
  // dump the memory
  uint8_t val;
  for (uint16_t addr = 0; addr < max_addr; addr++) {
    val = i2ceeprom.read(addr);
    if ((addr % 32) == 0) {
      Serial.print("\n 0x"); Serial.print(addr, HEX); Serial.print(": ");
    }
    Serial.print("0x"); 
    if (val < 0x10) 
      Serial.print('0');
    Serial.print(val, HEX); Serial.print(" ");
  }
}

void loop(void) {

}

I recommend using extEEPROM or DueFlashStorage. 73

Thank you for the reply.
do you have any experience with the setup i am using and what i am trying to do?
I will give this a shot.

Any advice on getting the DUE FLASH STORAGE to work properly before i embark on this?

Thank you
Charles

DueFlashStorage is very simple, you basically just need to call the write method.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.