EEPROM save sketch upload

Hi guys

Situation:

  • Arduino UNO R3, 328p
  • sketch upload via ISCP from ARUINO IDE via USBtinyISP
  • hence: no bootloader
  • sketch uses cpu internal EEPROM data

Process step:

  • I had to update the sketch, new functionalities
  • I will not overwrite EEPOM data during sketch update

I was googling a lot. But I have no clue how to bring my sketch on the atmel without erasing the EEPROM.

Possible steps:
1.) Write new bootloader via USBtinyISP, EEPROM Save in fuse -> no success / EEPROM emptied
1.a) once a bootloader is on: sketch uploaded via USB -> no EEPROM changed after board fuse update -> success
2.) Write new sketch via ISP directly to atmel using the Arduine IDE -> no success / EEPROM emptied

Any help is highly appreciated.

ATmega has a fuse to preserve EEPROM through chip erase. 328P - high fuse byte - bit#3 - EESAVE

Hey Budvar10.

a fuse to preserve EEPROM
yes, i know. But how to setup in Arduino IDE and/or command line? Do you have me step-by-step instruction? I failed with all my trys during last 2 months.

Here is a relevant link. I do still have issues to get the EEPROM save during sketch upload via Arduino IDE:

extracts from boards.txt, focus on uno.bootloader.high_fuses:

uno.upload.tool=avrdude
uno.upload.protocol=arduino
uno.upload.maximum_size=32256
uno.upload.maximum_data_size=2048
uno.upload.speed=115200
uno.bootloader.tool=avrdude
uno.bootloader.low_fuses=0xFF
uno.bootloader.high_fuses=0xD6
uno.bootloader.extended_fuses=0xFD
uno.bootloader.unlock_bits=0x3F
uno.bootloader.lock_bits=0x0F
uno.bootloader.file=optiboot/optiboot_atmega328.hex
uno.build.mcu=atmega328p
uno.build.f_cpu=16000000L
uno.build.board=AVR_UNO
uno.build.core=arduino
uno.build.variant=standard

but this setup wipes internal EEPROM during bootloader writing via ISP. Why?

And here is the avrdude.exe response reading out the atmel 328p with ISP:
C:\Program Files (x86)\Arduino\hardware\tools\avr\bin>avrdude -c usbtiny -p m328p -v -C "C:\Program Files (x86)\Arduino\hardware\tools\avr\etc\avrdude.conf"

avrdude: Version 6.3-20190619
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "C:\Program Files (x86)\Arduino\hardware\tools\avr\etc\avrdude.conf"

         Using Port                    : usb
         Using Programmer              : usbtiny
avrdude: usbdev_open(): Found USBtinyISP, bus:device: bus-0:\\.\libusb0-0001--0x1781-0x0c9f
         AVR Part                      : ATmega328P
         Chip Erase delay              : 9000 us
         PAGEL                         : PD7
         BS2                           : PC2
         RESET disposition             : dedicated
         RETRY pulse                   : SCK
         serial program mode           : yes
         parallel program mode         : yes
         Timeout                       : 200
         StabDelay                     : 100
         CmdexeDelay                   : 25
         SyncLoops                     : 32
         ByteDelay                     : 0
         PollIndex                     : 3
         PollValue                     : 0x53
         Memory Detail                 :

                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom        65    20     4    0 no       1024    4      0  3600  3600 0xff 0xff
           flash         65     6   128    0 yes     32768  128    256  4500  4500 0xff 0xff
           lfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           efuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           lock           0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

         Programmer Type : USBtiny
         Description     : USBtiny simple USB programmer, https://learn.adafruit.com/usbtinyisp
avrdude: programmer operation not supported

avrdude: Using SCK period of 10 usec
avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.03s

avrdude: Device signature = 0x1e950f (probably m328p)
avrdude: safemode: lfuse reads as FF
avrdude: safemode: hfuse reads as D6
avrdude: safemode: efuse reads as FD

this is in alignment with the boards.txt

Chip erase command erases flash and eeprom unless EESAVE is programmed. Problem is IDE settings. It needs to be changed or use avrdude directly from CMD.
Are you capable use avdude from command line?
For an inspiration you can use commands from IDE - log have to be set on in preferences.

but this setup wipes internal EEPROM during bootloader writing via ISP. Why?

Different setting is used for via ISP.

Budvar10:
Different setting is used for via ISP.

Ok cool. But where do I controll this? What are the config-files when using programmer in Arduino IDE to write down a new sketch usiong the fuse not to overwrite EEPROM. See my boards.txt above. I set EESAVE in boards.txt, but the IDE does empty the internal EEPROM when using ISP Programmer.

Here’s what the solution was for my case:

1.) backup EEPROM from operational Arduino UNO with avrdude:
C:\Program Files (x86)\Arduino\hardware\tools\avr\bin>avrdude -c usbtiny -p m328p -C “C:\Program Files (x86)\Arduino\hardware\tools\avr\etc\avrdude.conf” -U eeprom:r:Door2EEPROM.hex:i

2.) Write lfuse to Arduino UNO to new value H=0xD6
C:\Program Files (x86)\Arduino\hardware\tools\avr\bin>avrdude -c usbtiny -p m328p -C “C:\Program Files (x86)\Arduino\hardware\tools\avr\etc\avrdude.conf” -U hfuse:w:0xd6:m

3.) Check boards.txt in Arduino folder, if for UNO the fuse is 0xD6

4.) Upload via Arduino IDE over “use programmer” USBTiny ISP the code via ISP

==> No EEPROM is overwritten. Only the software code is written.

==> Issue solved!

Voila!
8)
Have a karma point.