element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Arduino Forum Flashing an ATMega328P/ATMega1284P with an AVRDragon
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • Replies 10 replies
  • Subscribers 390 subscribers
  • Views 1836 views
  • Users 0 members are here
  • avr
  • atmega
  • avrdragon
  • avrisp
Related

Flashing an ATMega328P/ATMega1284P with an AVRDragon

cstanton
cstanton over 8 years ago

This's frustrating.

 

So... push aside your thoughts as to why I'm doing this, and why I'm not doing it via any other fancy method. I'm attempting to do it with an AVRDragon and the chip on the board directly.

 

image

 

I've seen a number of guides on this online. They suggest connecting up a capacitor to the VCC line and a resistor to the RESET line, along with a 16mhz crystal oscillator to the ATMEGA328P chip.

 

It doesn't work.

 

stanto@portableone:/usr/share/arduino/hardware/arduino/bootloaders/optiboot$ make atmega328_isp ISPTOOL=dragon_isp

avrdude  -c dragon_isp -p atmega328p -P usb -b 115200 -e -u -U lock:w:0x3f:m -U efuse:w:0x05:m -U hfuse:w:0xDE:m -U lfuse:w:0xFF:m

 

 

avrdude: AVR device initialized and ready to accept instructions

 

 

Reading | ################################################## | 100% 0.15s

 

 

avrdude: Device signature = 0x1e950f (probably m328p)

avrdude: erasing chip

avrdude: reading input file "0x3f"

avrdude: writing lock (1 bytes):

 

 

Writing | ################################################## | 100% 0.06s

 

 

avrdude: 1 bytes of lock written

avrdude: verifying lock memory against 0x3f:

avrdude: load data lock data from input file 0x3f:

avrdude: input file 0x3f contains 1 bytes

avrdude: reading on-chip lock data:

 

 

Reading | ################################################## | 100% 0.05s

 

 

avrdude: verifying ...

avrdude: verification error, first mismatch at byte 0x0000

         0xff != 0x3f

avrdude: verification error; content mismatch

 

 

avrdude done.  Thank you.

 

 

Makefile:427: recipe for target 'isp' failed

make: *** [isp] Error 1

This is when I'm lucky. When I'm not so lucky I get this:

 

stanto@portableone:/usr/share/arduino/hardware/arduino/bootloaders/optiboot$ make atmega328_isp ISPTOOL=dragon_isp

avrdude  -c dragon_isp -p atmega328p -P usb -b 115200 -e -u -U lock:w:0x3f:m -U efuse:w:0x05:m -U hfuse:w:0xDE:m -U lfuse:w:0xFF:m

avrdude: jtagmkII_setparm(): bad response to set parameter command: RSP_FAILED

avrdude: jtagmkII_getsync(): ISP activation failed, trying debugWire

avrdude: jtagmkII_setparm(): bad response to set parameter command: RSP_DEBUGWIRE_SYNC_FAILED

avrdude: failed to sync with the AVR Dragon in ISP mode

 

 

avrdude done.  Thank you.

 

 

Makefile:427: recipe for target 'isp' failed

make: *** [isp] Error 1

What am I missing or doing wrong?

 

I've also had similar problems using an AVRISPmk2, and also trying to program an ATMEGA1284P, so I suspect there's something "obvious" I'm missing, or a step, and no matter how much I search all it says is that I should have an oscillator and cap. Gah.

 

Tips? Even if it's a step by step from scratch..

  • Sign in to reply
  • Cancel

Top Replies

  • cstanton
    cstanton over 8 years ago in reply to shabaz +2
    One of my thoughts was that avrdude was "at fault". However I couldn't find anything to corroborate that theory, I was very close to trying to grab the latest trunk of avrdude to check and it got far too…
  • cstanton
    cstanton over 8 years ago in reply to shabaz +1
    Results: - One atmega1284p is dead - HVPP let me erase the chip and reset the fuses, the fuse settings had been set in such a way thanks to the avrdude version change that ISP stopped working after trying…
  • cstanton
    cstanton over 8 years ago in reply to shabaz +1
    Yeah as you can see, there's an unhappy capacitor... Still, I had to actually revert to avrdude 5.1 to be able to flash the atmega1284p, when using avrdude 6.3 the program really didn't want to talk with…
  • shabaz
    shabaz over 8 years ago

    Hi Christopher,

     

    I've not used the ATmega for a long time, many years (and I too found the tools like genuine AVRisp Mk2 to be unreliable, even the Olimex clone worked better!) so I'm only guessing unfortunately: I'm wondering if it could be this, the command line has the text "lock:w:0x3f" and the first bit of debug has this:

             0xff != 0x3f
    avrdude: verification error; content mismatch

     

    According to the ATmega datasheet, only 6 bits in the byte are these 'lock bits', so 0x3f would sound right, if avrdude is functioning. However, the datasheet says that the unused bits in the byte are read as '1', so perhaps avrdude isn't being smart enough to ignore the unused bits, hence it thinks that 0xff is not 0x3f.

    Looks like someone had such an issue in Aug 2016: https://github.com/arduino/avrdude-build-script/issues/2

    so maybe either the avrdude executable is too old, or they may have changed it so that the command line needs to say "lock:w:0xff" instead of "lock:w:0x3f".

    image

    It is crazy though if they changed the CLI so that now it is not backward compatible and all the people who typed 0x3f now have to type 0xff. But sometimes engineers do such irritating things! : (

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • cstanton
    cstanton over 8 years ago in reply to shabaz

    One of my thoughts was that avrdude was "at fault". However I couldn't find anything to corroborate that theory, I was very close to trying to grab the latest trunk of avrdude to check and it got far too late in the day.

     

    I find the best bugs, as if this is literally being patched now, also. Thanks, I'll see about reverting avrdude and/or trying a patched version, and/or changing the parameters to suit. Damn thing.

     

    There were other faults relating to synchronisation which I was also having, so will likely update if they resurface.

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • Cancel
  • cstanton
    cstanton over 8 years ago in reply to shabaz

    stanto@portableone:/etc/apt$ sudo avrdude -p atmega1284p -P usb -c dragon_isp -U flash:r:flash.bin:r

    avrdude: jtagmkII_setparm(): bad response to set parameter command: RSP_FAILED

    avrdude: jtagmkII_getsync(): ISP activation failed, trying debugWire

    avrdude: jtagmkII_setparm(): bad response to set parameter command: RSP_DEBUGWIRE_SYNC_FAILED

    avrdude: failed to sync with the AVR Dragon in ISP mode

    avrdude: jtagmkII_close(): timeout/error communicating with programmer (status -1)

     

     

    avrdude done.  Thank you.

    I came back to working with the hardware, and couldn't talk with the chip again, in fact, I swapped it out for an atmega1284 and re-wired it and this is the type of message I get, still, so even without setting any fuses.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • shabaz
    shabaz over 8 years ago in reply to cstanton

    I'm wondering if it is worth trying the AVR Studio capability for programming with AVRDragon, just to rule out CLI and/or avrdude version.

    I've not used AVRdragon, but I saw a decent video here, although you probably already may have found this while troubleshooting: https://www.youtube.com/watch?v=yJo29VMXt90

    Also, just speculation (I've never used an AVRdragon) I suppose there is also the possibility that the AVRdragon firmware has some mismatch with avrdude or AVR Studio too : (

    I don't know if AVRdragon needs upgrading, or even has a way to upgrade.

    Also, since avrdude is third party software, it may be better to try the official AVR Studio anyway, since it perhaps may identify if AVRdragon needs upgrading.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • cstanton
    cstanton over 8 years ago in reply to shabaz

    Yep, tried the official AVR/Atmel Studio. Still doesn't talk to the chip, Atmel Studio happily upgraded the avrdragon firmware, so that's been re-written. Atmel studio refuses to work with any programmer which has an out of date firmware. Which makes me think there's something wrong with the circuit, but I did wire it up as per the video you also found.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • shabaz
    shabaz over 8 years ago in reply to cstanton

    I see : ( I can't think what it could be (assuming it isn't a faulty AVRdragon board). Faulty breadboard maybe? The jumper cables can get faulty too (some of the cheaper ones have broken wires yet where they were badly stripped, yet from the outside they appear fine. But if you've reattempted with new wiring it is unlikely to be that too. It is interesting because the first debug does seem to show that it sometimes almost works, since it recognised that it received 0xff. I'm wondering if it is an intermittent hardware fault that occasionally makes contact.

     

    Also, although it's otherwise a good video, one thing missing there is a 100nF cap directly across the supply rails as close to the ATmega chip as possible. You've probably already done that but if you have not then it could be worth a try. I still have an avrISP Mk2 somewhere, so I can dig that out to attempt this tomorrow too, if I find an ATmega.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • cstanton
    cstanton over 8 years ago in reply to shabaz

    Thanks, well I started pulling an atmega out of an arduino to cross-check. I think I'll use this as an opportunity to check the ISP lines with an oscilloscope as well.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • cstanton
    cstanton over 8 years ago in reply to shabaz

    Results:

    - One atmega1284p is dead

    - HVPP let me erase the chip and reset the fuses, the fuse settings had been set in such a way thanks to the avrdude version change that ISP stopped working after trying to flash it

    - The sanguinololu board these chips were in has some other fault I'm having to diagnose, the voltage regulator has started overheating and it's bricking the chips when trying to use the FTDI controller to flash it..

     

    sigh.

     

    Thanks for your help!

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
  • shabaz
    shabaz over 8 years ago in reply to cstanton

    Hi Christopher,

     

    I see : ( that's unfortunate. Let me know if you need me to try on a breadboard any particular avrdude version, I did manage to find an ATmega chip. But it sounds like you've got identified the root cause, i.e. board fault.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • cstanton
    cstanton over 8 years ago in reply to shabaz

    image

    Yeah as you can see, there's an unhappy capacitor...

     

    Still, I had to actually revert to avrdude 5.1 to be able to flash the atmega1284p, when using avrdude 6.3 the program really didn't want to talk with the chip properly

     

    image

     

    Also the avr dragon is in itself temperamental. Switching out atmega1284ps would sometimes result in a chip not being identified until reseated/some sort of PC reboot/device power cycling dance was performed.

     

    image

     

    And although I had a spare sanguinololu, attempting to flash the board using avrdude in the arduino IDE wasn't happening at all.

     

    In fact, attempting to flash the atmega1284p via avrdragon as a programmer from the arduino IDE brought up a different problem, the arduino IDE runs avrdude twice in quick succession and the second time will always fail, and so it looks like it overall fails, when this isn't actually the case. The verbose log (and a stack trace) shows that the first instance works, the second instance doesn't work (and this has been checked by manually running the commands) because the avrdragon needs time to settle after the first communication.

     

    So many problems. This is crazy.

     

    As a side note, I did manage to unbrick the atmega328ps which I had been tinkering with. Their fuses were finally reset and the bootloaders reflashed.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube