# Odd EEprom issue

**URL:** <https://forum.arduino.cc/t/odd-eeprom-issue/1096853>\
**Category:** Programming\
**Created:** [March 2, 2023, 11:36am UTC](https://forum.arduino.cc/t/odd-eeprom-issue/1096853 "2023-03-02T11:36:27Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon64083092](https://avatars.discourse-cdn.com/v4/letter/a/3bc359/32.png) [@anon64083092](https://forum.arduino.cc/u/anon64083092)\
**Post date:** [March 2, 2023, 11:36am UTC](https://forum.arduino.cc/t/odd-eeprom-issue/1096853/1 "2023-03-02T11:36:27Z")

</div>

Hello all

I have a circuit using an ATmega328p TQFN chip. All well and dandy

At the beginning of my routine, it accesses data from the EEPROM.

But, it's not remembering it (or something else is going on). I have tested the read and write and its fine.

At the end of my setup, I recall the data:

```cpp

 //EEPROMreset(); // Perform an EEPROM reset. Uncomment to reset

  for (currentPin = 0; currentPin < pinCount; currentPin++) { // Get all the EEPROM values
    TXadd[currentPin] = EEPROM.read(currentPin);
  }

  for (currentPin = 0; currentPin < pinCount; currentPin++) {
    TXval[currentPin] = EEPROM.read(currentPin + 10);
  }

  for (currentPin = 0; currentPin < pinCount; currentPin++) {
    TXmode[currentPin] = EEPROM.read(currentPin + 20);
  }

  for (currentPin = 0; currentPin < pinCount; currentPin++) {
    TXdelay[currentPin] = EEPROM.read(currentPin + 30);
  }

```

But this doesn't recall any data.

I have to go and write the data first (I uncomment the EEPROMreset(); in the retrieval code above ) using:

```cpp
void EEPROMreset() {

  for (byte i = 0; i <= 9; i++) { // Store default addresses (Default 1-10)
    EEPROM.write(i, (i + 1));
  }

  for (byte i = 10; i <= 19; i++) { // Store default ON transmitted value (Default 255)
    EEPROM.write(i, 255);
  }

  for (byte i = 20; i <= 29; i++) { // Store default mode (Default momentary)
    EEPROM.write(i, 0);
  }

  for (byte i = 30; i <= 39; i++) { // Store timer delay in seconds (Default 1 second)
    EEPROM.write(i, 1);
  }
}

```

I am uploading using a USBasp if that makes any difference.  
I am not sure why it's not recalling the data.

If I use the write routine above (void EEPROMreset()) with different variables, they are the ones it recalls. But only if I write them every boot.

Ideas?

---

<div class="post-metadata">

**Author:** ![anon64083092](https://avatars.discourse-cdn.com/v4/letter/a/3bc359/32.png) [@anon64083092](https://forum.arduino.cc/u/anon64083092)\
**Post date:** [March 2, 2023, 11:48am UTC](https://forum.arduino.cc/t/odd-eeprom-issue/1096853/2 "2023-03-02T11:48:42Z")

</div>

I should add that I am uploading using Minicore, and selecting retain EEPROM in the tools drop-down

---

<div class="post-metadata">

**Author:** ![anon64083092](https://avatars.discourse-cdn.com/v4/letter/a/3bc359/32.png) [@anon64083092](https://forum.arduino.cc/u/anon64083092)\
**Post date:** [March 2, 2023, 2:57pm UTC](https://forum.arduino.cc/t/odd-eeprom-issue/1096853/3 "2023-03-02T14:57:17Z")

</div>

It erases at boot when programmed via ISP.  
Set a flag to reload the data once after programming now

---

<div class="post-metadata">

**Author:** ![mrburnette](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/mrburnette/32/702556_2.png) [@mrburnette](https://forum.arduino.cc/u/mrburnette)\
**Post date:** [March 2, 2023, 4:07pm UTC](https://forum.arduino.cc/t/odd-eeprom-issue/1096853/4 "2023-03-02T16:07:47Z")

</div>

we often forget that the EEPROM is a separate device inside AVR. AVRDUDE is invoked separately for different sections of the uC

```cpp
ECHO Creating hexadecimal binary files of ATmel328P contents...
>stdout.log 2>&1 (
avrdude -c arduino -P com9 -p ATMEGA328P -b 19200 -U flash:r:%temp%\backup_flash.hex:i
ECHO flash has been sAVED to backup_flash.hex
avrdude -c arduino -P com9 -p ATMEGA328P -b 19200 -U eeprom:r:%temp%\backup_eeprom.hex:i
ECHO eeprom has been SAVED to backup_eerpom.hex
avrdude -c arduino -P com9 -p ATMEGA328P -b 19200 -U hfuse:r:%temp%\backup_hfuse.hex:i
ECHO hfuse has been SAVED to backup_hfuse.hex
avrdude -c arduino -P com9 -p ATMEGA328P -b 19200 -U lfuse:r:%temp%\backup_lfuse.hex:i
ECHO lfuse has been SAVED to backup_lfuse.hex
avrdude -c arduino -P com9 -p ATMEGA328P -b 19200 -U efuse:r:%temp%\backup_efuse.hex:i
ECHO efuse has been SAVED to backup_efuse.hex
)
ECHO Hexadecimal files created.

```

[Full batch listing here](https://forum.arduino.cc/t/copy-n-paste-arduino-firmware/178469)

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [August 29, 2023, 4:08pm UTC](https://forum.arduino.cc/t/odd-eeprom-issue/1096853/5 "2023-08-29T16:08:34Z")

</div>

Closed on August 29, 2023, 4:08pm UTC

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