Sketches run at very slow frequencyu after uploading with Atmel ICE on ATmega328p

Hi,
I have been programming smd 32 pins atmega328p’s for a while and everything worked perfect until I might have misclicked or misplugged something tonight. It is chaos. I manage to upload, but my upload times are super slow.
Here is a verbose upload

avrdude: Version 6.3, compiled on Sep 12 2016 at 17:24:16
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "C:\Users\Jean-Christophe\.platformio\packages\tool-avrdude\avrdude.conf"

         Using Port                    : usb
         Using Programmer              : atmelice_isp
         Overriding Baud Rate          : 115200
avrdude: usbdev_open(): Found Atmel-ICE CMSIS-DAP, serno: J42700010786
avrdude: Found CMSIS-DAP compliant device, using EDBG protocol
         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 : JTAG3_ISP
         Description     : Atmel-ICE (ARM/AVR) in ISP mode
         Vtarget         : 5.0 V
         SCK period      : 8.00 us

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e950f (probably m328p)
avrdude: safemode: hfuse reads as D9
avrdude: safemode: efuse reads as FF
avrdude: erasing chip
avrdude: reading input file ".pio\build\ATmega328P\firmware.hex"
avrdude: writing flash (1884 bytes):

Writing | ################################################## | 100% 0.55s

avrdude: 1884 bytes of flash written
avrdude: verifying flash memory against .pio\build\ATmega328P\firmware.hex:
avrdude: load data flash data from input file .pio\build\ATmega328P\firmware.hex:
avrdude: input file .pio\build\ATmega328P\firmware.hex contains 1884 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 0.54s

avrdude: verifying ...
avrdude: 1884 bytes of flash verified

avrdude: safemode: hfuse reads as D9
avrdude: safemode: efuse reads as FF
avrdude: safemode: Fuses OK (E:FF, H:D9, L:62)

avrdude done.  Thank you.

========================================================== [SUCCESS] Took 12.85 seconds ==========================================================

I am not sure what caused the problem. It is not just the chip, because I get the same problem for every new chip I try to upload to. It is either my platformIO setup with fuses or whatever that changed or my atmel ICE itself (maybe its broken?) I have 3 ideas.

  1. I had my atmega and everything hooked up at 3v3 and had an I2C LCD. SDA and SCL were at 3v3 but I decided to plug the VCC at 5v. Maybe the SDA and SCL pins of the LCD at 5v bugged something on the chip or even on the atmel ICE?

  2. Maybe I clicked on set fuses and something changed in the code/ICE

  3. Maybe it has something to do with that safemode in my upload script. I do not recall seeing this before.

Here is my .ini when uploading with ICE: I added the two last lines after the bug in hope it would resolve but no. (Anyway [env:ATmega328P] doesn’t even recognize oscillator = external)

[env:ATmega328P]

platform = atmelavr

board = ATmega328P

framework = arduino

upload_protocol = atmelice_isp

upload_flags = -e

upload_port = usb

board_build.f_cpu = 16000000L

oscillator = external

Also, is there memory on the atmel ICE? Like does it save how to set fuses when it uploads or it is entirely up to PlatformIO? Im just really scared I broke my ICE. Its too expensive to buy a new one… Thanks!

avrdude is telling you the fuse settings… it looks like you haven’t set the fuse settings so it’s still using the factory default (i.e. internal 8mhz oscillator).

http://www.engbedded.com/fusecalc?P=ATmega328P&V_LOW=0x62&V_HIGH=0xD9&V_EXTENDED=0xFF&O_HEX=Apply+values

Since you were trying to set F_CPU to 16Mhz… I take it you’re using a external 16Mhz crystal, and the standard Arduino Uno fuse values should suffice?

http://www.engbedded.com/fusecalc?P=ATmega328P&V_LOW=0xFF&V_HIGH=0xDE&V_EXTENDED=0x05&O_HEX=Apply+values

As far as the oscillator parameter, it looks like the documentation needs an update, as it neglects to mention those parameters start with board_hardware. … ie. board_hardware.oscillator = external.

I don’t think the Atmel ICE has any memory as such… it’s not like a Pickit2 that can self-program MCUs … it’ll only set fuse values, etc to whatever you specifically instruct it to.

avrdude: safemode will always have been there… it’s just an indication of what the current fuse values are, whilst letting you know it hasn’t touched them.

1 Like

Thanks ! I f found the solution with your link and explained it on a post where I detail how to work with atmel ICE on PIO. It was a fuse problem, I just dont know why my fuses changed randomly after weeks of use (maybe I clicked on set fuses accidentally) Thanks again for your help.

solution here: Setting up Atmel-ICE with PlatformIO using ATmega328p – Cyan Sensors

2 Likes

Fantastic! :slight_smile: I’ll have to bookmark that page as a reminder next time I drag my Atmel ICE out and have to start scratching my head trying to figure out why it won’t behave! :wink: I’ve had more luck with the much cheaper USBAsps, but sprung for a genuine Atmel ICE since I wanted have the option of doing debugging. I’m now starting to think I should have waited a bit longer, as it looks like the PICkit 4 will have AVR support (it already has SAM support) and may also support high voltage programming / reset… making it far superior (and cheaper!!) than the ICE. Ah well… maybe an excuse to get another programmer? :laughing: