Unusually long programming times when programming ATmega328P

Go To Last Post
7 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm programming an ATmega328p using avrdude, and to program it with a program size of 3074 bytes, I am waiting 13 seconds. That seems pretty dang long to me.

I have tried using both the internal oscillator at 8MHz, and an external oscillator at 8MHz. CKDIV8 is unprogrammed. I'm not sure why 3kb is taking so long. I remember it being much shorter for some reason.

This topic has a solution.
Last Edited: Sat. Jun 5, 2021 - 08:26 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Side note, here is the output of avrdude:

avrdude -c atmelice_isp -p m328p -U flash:w:debug.hex

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.01s

avrdude: Device signature = 0x1e950f (probably m328p)
avrdude: NOTE: "flash" memory has been specified, an erase cycle will be performed
         To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: reading input file "debug.hex"
avrdude: input file debug.hex auto detected as Intel Hex
avrdude: writing flash (3074 bytes):

Writing | ################################################## | 100% 12.57s

avrdude: 3074 bytes of flash written
avrdude: verifying flash memory against debug.hex:
avrdude: load data flash data from input file debug.hex:
avrdude: input file debug.hex auto detected as Intel Hex
avrdude: input file debug.hex contains 3074 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 13.06s

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

avrdude: safemode: Fuses OK (E:FF, H:D9, L:E0)

avrdude done.  Thank you.

And the programmer that I am using is an Atmel-ICE

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Seriously.   LFUSE = 0xE0 means External Clock on XTAL1 pin

 

What is your external clock ?

Without a clock,  I would not expect anything to work.

 

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

david.prentice wrote:

Seriously.   LFUSE = 0xE0 means External Clock on XTAL1 pin

 

What is your external clock ?

Without a clock,  I would not expect anything to work.

 

David.

 

as mentioned in the post, the external clock signal is 8MHz on the clock pin XTAL1. 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

First off.  Is your external clock really 8MHz

 

I read the flash memory from an ATmega168 running from an external 16MHz clock (on a STK500)

avrdude -c atmelice_isp -p ATmega168 -U flash:r:bum.hex:i -B 50

This took 27.86s to read the 16kB i.e. with SCK period 50us (SPI = 20kHz)

 

I subsequently tried

avrdude -c atmelice_isp -p ATmega168 -U flash:r:bum.hex:i

This also took 27.86s because ATMEL-ICE remembers the previous SCK setting.

 

I then tried SCK = 2MHz i.e. suitable for an 8MHz AVR

avrdude -c atmelice_isp -p ATmega168 -U flash:r:bum.hex:i -B 0.5

This took 1.33s

 

You will get a similar feature with writing 3kB to a ATmega328P

 

Note that if you use a regular Chinese USBASP it will use the "best" SCK frequency automatically.

 

David.

Last Edited: Sat. Jun 5, 2021 - 11:41 AM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

david.prentice wrote:

First off.  Is your external clock really 8MHz

Yes. Siglent SDG 2042x is the generator, and verified with a siglent SDS1104x-e.

 

Either way, the solution was to just set `-B` to a static value. I set it to `-B 1` which drops it to about 0.16s. I don't know why the atmel ICE wasn't taking the best speed option, but whatever. Solved now.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Traditionally,  Atmel programmers store parameters in EEPROM.   e.g. if you tell the STK500 to generate 3.3V it will generate 3.3V

 

And every time you switch the STK500 on,  it will generate 3.3V

If you tell it to generate 2.5V it will store this "2.5V" value in EEPROM.   And generate 2.5V

 

Likewise with the STK500 external F_CPU clock frequency.

Or with the SCK frequency for ISP Serial programming.

 

i.e. it reads from EEPROM to set the current values whenever you switch the STK500 on.

 

Likewise,  AVRISP-2, STK500, STK600, ..., JTAGICE-2, DRAGON, ...

Ok,  these devices don't all have programmable voltage or clocks.   But they all store the SCK frequency.

 

David.

Last Edited: Sat. Jun 5, 2021 - 09:31 PM