Recovering "External 16MHz"-fused mega2560

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

I have a board that's all working with a mega2560 configured to use the Arduino MegaCore (https://github.com/MCUdude/MegaCore) and that can be programmed through a FT232 controller.

 

The last step for me was ensuring that the clock ran at 16MHz. I kept using the "8MHz internal" fuse setting when burning the bootloader in testing, because I didn't want my clock circuit as an extra variable when debugging other things. Now that everything else is all sorted, I tried the following steps:

 

Hook up ArduinoISP (directly to MOSI, MISO, SCK)

Select "Clock: 16MHz External"

Burn Bootloader

 

And I believe the bootloader burned, but failed in the verify step (I'd show a log but I can't recreate it).

After that burn, I can't burn bootloader or program via the FT232 or ArduinoISP. Most likely, the clock the micro is expecting isn't there, and it's dead.

 

Here's the output for all subsequent tries of Burn Bootloader with the ISP.

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

         System wide configuration file is "C:\Users\~\AppData\Local\Arduino15\packages\MegaCore\hardware\avr\2.0.1/avrdude.conf"

         Using Port                    : COM5
         Using Programmer              : arduino
         Overriding Baud Rate          : 19200
         AVR Part                      : ATmega2560
         Chip Erase delay              : 9000 us
         PAGEL                         : PD7
         BS2                           : PA0
         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    10     8    0 no       4096    8      0  9000  9000 0x00 0x00
           flash         65    10   256    0 yes    262144  256   1024  4500  4500 0x00 0x00
           lfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           efuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           lock           0     0     0    0 no          1    0      0  9000  9000 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 : Arduino
         Description     : Arduino
         Hardware Version: 2
         Firmware Version: 1.18
         Topcard         : Unknown
         Vtarget         : 0.0 V
         Varef           : 0.0 V
         Oscillator      : Off
         SCK period      : 0.1 us

avrdude: AVR device initialized and ready to accept instructions

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

avrdude: Device signature = 0xffffff (retrying)

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

avrdude: Device signature = 0xffffff (retrying)

Error while burning bootloader.
Reading | ################################################## | 100% 0.01s

avrdude: Device signature = 0xffffff
avrdude: Yikes!  Invalid device signature.
         Double check connections and try again, or use -F to override
         this check.


avrdude done.  Thank you.

 

I do have a 16MHz crystal in the circuit. It's one of those three-pin deals, connected as specified in the datasheet: http://ww1.microchip.com/downloa...

 

But, perhaps just having an external clock is not what is required by "16MHz external", because it is not an active input. Do I need an externally driven clock to use that feature and recover my chip? Or is there some other combination of settings I could use to save the micro here?

 

Thanks,

 

 

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

It is easy to mis-set the Fuses.

 

As you already suggested, try injecting a clock signal into the Xtal pin on the micro.

It doesn't have to be 16 MHz, actually it can be just about anything, (as long is it is roughly a square wave).

 

I am on the wrong computer for looking it up, but you have two Xtal pins on the micro, so inject it into Xtal 1, (I think, I can't recall).

 

Note that you need a common ground connection as well as the clock signal.

 

You could use another Arduino board and just tight loop toggling a pin High/Low to generate your external clock signal.

 

The programmer's programming speed must also be < 1/4 of the (injected) clock frequency for the programmer to work.

 

Once your programmer can communicate with the uC again, verify that you can read the chip's Signature, then reset the clock Fuses.

I don't know what the correct terminology is for the Arduino IDE for using an external Xtal, (not an external clock source).

 

Note, for the record, that your 3-Pin "Xtal" is likely a "resonator", not a "crystal", but that doesn't really matter for now, it is just a matter of correctness.

 

Report back on your success!

 

JC

 

Edit:

BTY, Cliff has a full tutorial on un-bricking AVRs in the Tutorial section, in case you need more info / details / options.

 

Last Edited: Thu. Feb 6, 2020 - 08:40 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

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

DocJC wrote:
...  Xtal 1,  ....
XTAL2 then XTAL1, if need be, per a 11 step procedure :

Pololu - 5.10. Using the clock output to revive AVRs

also check all VCC and GND pairs (keep VCC off BOD and POR) and check the reset signal (reset only via AVR ISP, not via an external supervisor or watchdog unless there's a reset pass-through)

 

"Dare to be naïve." - Buckminster Fuller

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

Okay, thanks - it looks like my situation neatly matches one of the common problems. I will test with an external clock source to recover the micro once I get a chance.

 

By the way, you mention in the tutorial about possible invalid configurations for an attached crystal resonator. This is most likely what's happening for me. I found a fuse calculator that should most likely help on my second fusing foray: http://eleccelerator.com/fusecal...

However I'm still not clear on a few details (to use a 16MHz resonator hooked up to XTAL1/XTAL2 as specified in the datasheet):

  • Is the setting "External Crystal Osc." the proper one?
  • I assume my situation would call for one of those "8-to-?" MHz presets?
  • How do I compute startup-time and does it matter?
  • Are there any other considerations I should make to ensure I get a clean 16MHz signal?

 

Everything else looks clear enough to me here...

 

EDIT: Oh, and more of a curiosity question. Since I will have to do some precise fusing, I don't think using the obscure and opaque MegaCore/Arduino IDE settings are going to do the trick. But do you know if it is actually capable of more fine control and I'm missing something? If not, I can modify go through a Makefile I have that invokes avrdude with the fuse options manually, but I was just wondering.

 

Thanks.

Last Edited: Thu. Feb 6, 2020 - 09:43 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


Most AVRFreaks use this site: http://www.engbedded.com/fusecalc/

Empty Set wrote:
Is the setting "External Crystal Osc." the proper one?

Its the last one in the list,:

Make sure you UNcheck the CKDIV8 fuse above

Empty Set wrote:
How do I compute startup-time and does it matter?

Unless you know you need something else, chose the longest time as shown above.

Empty Set wrote:
Are there any other considerations I should make to ensure I get a clean 16MHz signal?

keep the gnd traces short, ie. use a gnd plane, read app note AVR042!

 

Jim

 

 

 

 

 

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

Empty Set wrote:
I don't think using the obscure and opaque MegaCore/Arduino IDE settings are going to do the trick.
Arduinos all set the fuses for any particular AVR to exactly the same thing - it's part of what makes Arduinos so easy - tjhe end user never needs to worry about such things but in an Arduino installation you can easily see what these values are (and copy them to a standalone invocation of avrdude if that's what you want). Look for the file "boards.txt" which should be in intall_dir\hardware\arduino\avr:

D:\arduino-1.8.8\hardware\arduino\avr>grep _fuses boards.txt
yun.bootloader.low_fuses=0xff
yun.bootloader.high_fuses=0xd8
yun.bootloader.extended_fuses=0xfb
uno.bootloader.low_fuses=0xFF
uno.bootloader.high_fuses=0xDE
uno.bootloader.extended_fuses=0xFD
diecimila.bootloader.low_fuses=0xFF
diecimila.menu.cpu.atmega328.bootloader.high_fuses=0xDA
diecimila.menu.cpu.atmega328.bootloader.extended_fuses=0xFD
diecimila.menu.cpu.atmega168.bootloader.high_fuses=0xdd
diecimila.menu.cpu.atmega168.bootloader.extended_fuses=0xF8
nano.menu.cpu.atmega328.bootloader.low_fuses=0xFF
nano.menu.cpu.atmega328.bootloader.high_fuses=0xDA
nano.menu.cpu.atmega328.bootloader.extended_fuses=0xFD
nano.menu.cpu.atmega328old.bootloader.low_fuses=0xFF
nano.menu.cpu.atmega328old.bootloader.high_fuses=0xDA
nano.menu.cpu.atmega328old.bootloader.extended_fuses=0xFD
nano.menu.cpu.atmega168.bootloader.low_fuses=0xff
nano.menu.cpu.atmega168.bootloader.high_fuses=0xdd
nano.menu.cpu.atmega168.bootloader.extended_fuses=0xF8
mega.bootloader.low_fuses=0xFF
mega.menu.cpu.atmega2560.bootloader.high_fuses=0xD8
mega.menu.cpu.atmega2560.bootloader.extended_fuses=0xFD
mega.menu.cpu.atmega1280.bootloader.high_fuses=0xDA
mega.menu.cpu.atmega1280.bootloader.extended_fuses=0xF5
megaADK.bootloader.low_fuses=0xFF
megaADK.bootloader.high_fuses=0xD8
megaADK.bootloader.extended_fuses=0xFD
leonardo.bootloader.low_fuses=0xff
leonardo.bootloader.high_fuses=0xd8
leonardo.bootloader.extended_fuses=0xcb
leonardoeth.bootloader.low_fuses=0xff
leonardoeth.bootloader.high_fuses=0xd8
leonardoeth.bootloader.extended_fuses=0xcb
micro.bootloader.low_fuses=0xff
micro.bootloader.high_fuses=0xd8
micro.bootloader.extended_fuses=0xcb
esplora.bootloader.low_fuses=0xff
esplora.bootloader.high_fuses=0xd8
esplora.bootloader.extended_fuses=0xcb
mini.bootloader.low_fuses=0xff
mini.menu.cpu.atmega328.bootloader.high_fuses=0xd8
mini.menu.cpu.atmega328.bootloader.extended_fuses=0xFD
mini.menu.cpu.atmega168.bootloader.high_fuses=0xdd
mini.menu.cpu.atmega168.bootloader.extended_fuses=0xF8
ethernet.bootloader.low_fuses=0xff
ethernet.bootloader.high_fuses=0xde
ethernet.bootloader.extended_fuses=0xFD
fio.bootloader.low_fuses=0xFF
fio.bootloader.high_fuses=0xDA
fio.bootloader.extended_fuses=0xFD
bt.bootloader.low_fuses=0xff
bt.menu.cpu.atmega328.bootloader.high_fuses=0xd8
bt.menu.cpu.atmega328.bootloader.extended_fuses=0xFD
bt.menu.cpu.atmega168.bootloader.high_fuses=0xdd
bt.menu.cpu.atmega168.bootloader.extended_fuses=0xF8
LilyPadUSB.bootloader.low_fuses=0xff
LilyPadUSB.bootloader.high_fuses=0xd8
LilyPadUSB.bootloader.extended_fuses=0xce
lilypad.menu.cpu.atmega328.bootloader.low_fuses=0xFF
lilypad.menu.cpu.atmega328.bootloader.high_fuses=0xDA
lilypad.menu.cpu.atmega328.bootloader.extended_fuses=0xFD
lilypad.menu.cpu.atmega168.bootloader.low_fuses=0xe2
lilypad.menu.cpu.atmega168.bootloader.high_fuses=0xdd
lilypad.menu.cpu.atmega168.bootloader.extended_fuses=0xF8
pro.menu.cpu.16MHzatmega328.bootloader.low_fuses=0xFF
pro.menu.cpu.16MHzatmega328.bootloader.high_fuses=0xDA
pro.menu.cpu.16MHzatmega328.bootloader.extended_fuses=0xFD
pro.menu.cpu.8MHzatmega328.bootloader.low_fuses=0xFF
pro.menu.cpu.8MHzatmega328.bootloader.high_fuses=0xDA
pro.menu.cpu.8MHzatmega328.bootloader.extended_fuses=0xFD
pro.menu.cpu.16MHzatmega168.bootloader.low_fuses=0xff
pro.menu.cpu.16MHzatmega168.bootloader.high_fuses=0xdd
pro.menu.cpu.16MHzatmega168.bootloader.extended_fuses=0xF8
pro.menu.cpu.8MHzatmega168.bootloader.low_fuses=0xc6
pro.menu.cpu.8MHzatmega168.bootloader.high_fuses=0xdd
pro.menu.cpu.8MHzatmega168.bootloader.extended_fuses=0xF8
atmegang.menu.cpu.atmega168.bootloader.low_fuses=0xff
atmegang.menu.cpu.atmega168.bootloader.high_fuses=0xdd
atmegang.menu.cpu.atmega168.bootloader.extended_fuses=0xF8
atmegang.menu.cpu.atmega8.bootloader.low_fuses=0xdf
atmegang.menu.cpu.atmega8.bootloader.high_fuses=0xca
atmegang.menu.cpu.atmega8.bootloader.extended_fuses=
robotControl.bootloader.low_fuses=0xff
robotControl.bootloader.high_fuses=0xd8
robotControl.bootloader.extended_fuses=0xcb
robotMotor.bootloader.low_fuses=0xff
robotMotor.bootloader.high_fuses=0xd8
robotMotor.bootloader.extended_fuses=0xcb
gemma.bootloader.low_fuses=0xF1
gemma.bootloader.high_fuses=0xD5
gemma.bootloader.extended_fuses=0xFE
circuitplay32u4cat.bootloader.low_fuses=0xff
circuitplay32u4cat.bootloader.high_fuses=0xd8
circuitplay32u4cat.bootloader.extended_fuses=0xcb
yunmini.bootloader.low_fuses=0xff
yunmini.bootloader.high_fuses=0xd8
yunmini.bootloader.extended_fuses=0xfb
chiwawa.bootloader.low_fuses=0xff
chiwawa.bootloader.high_fuses=0xd8
chiwawa.bootloader.extended_fuses=0xfb
one.bootloader.low_fuses=0xff
one.bootloader.high_fuses=0xd8
one.bootloader.extended_fuses=0xfb
unowifi.bootloader.low_fuses=0xFF
unowifi.bootloader.high_fuses=0xDE
unowifi.bootloader.extended_fuses=0x05

You can see from that, for example, that the mega (2560) fuses are D8/FD

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

Thanks for the help everyone. I managed to apply an externally driven signal and re-fuse the bootloader, first with the default settings used when running the "Burn Bootloader" command, then with the following settings: Lfuse 0xFF, Hfuse 0x99, Efuse 0xFF, which looks proper given the suggestions you've made above.

 

Here was the avrdude command + output for that sequence:

"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avrdude" -CC:\Users\~\AppData\Local\Arduino15\packages\MegaCore\hardware\avr\2.0.1/avrdude.conf -v -patmega2560 -carduino -PCOM5 -b19200 -e -Ulock:w:0x3f:m -Uefuse:w:0xff:m -Uhfuse:w:0x99:m -Ulfuse:w:0xff:m

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

         System wide configuration file is "C:\Users\~\AppData\Local\Arduino15\packages\MegaCore\hardware\avr\2.0.1/avrdude.conf"

         Using Port                    : COM5
         Using Programmer              : arduino
         Overriding Baud Rate          : 19200
         AVR Part                      : ATmega2560
         Chip Erase delay              : 9000 us
         PAGEL                         : PD7
         BS2                           : PA0
         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    10     8    0 no       4096    8      0  9000  9000 0x00 0x00
           flash         65    10   256    0 yes    262144  256   1024  4500  4500 0x00 0x00
           lfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           efuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           lock           0     0     0    0 no          1    0      0  9000  9000 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 : Arduino
         Description     : Arduino
         Hardware Version: 2
         Firmware Version: 1.18
         Topcard         : Unknown
         Vtarget         : 0.0 V
         Varef           : 0.0 V
         Oscillator      : Off
         SCK period      : 0.1 us

avrdude: AVR device initialized and ready to accept instructions

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

avrdude: Device signature = 0x1e9801 (probably m2560)
avrdude: safemode: lfuse reads as E2
avrdude: safemode: hfuse reads as D6
avrdude: safemode: efuse reads as FD
avrdude: erasing chip
avrdude: reading input file "0x3f"
avrdude: writing lock (1 bytes):

Writing | ################################################## | 100% 0.01s

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.01s

avrdude: verifying ...
avrdude: 1 bytes of lock verified
avrdude: reading input file "0xff"
avrdude: writing efuse (1 bytes):

Writing | ################################################## | 100% 0.02s

avrdude: 1 bytes of efuse written
avrdude: verifying efuse memory against 0xff:
avrdude: load data efuse data from input file 0xff:
avrdude: input file 0xff contains 1 bytes
avrdude: reading on-chip efuse data:

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

avrdude: verifying ...
avrdude: 1 bytes of efuse verified
avrdude: reading input file "0x99"
avrdude: writing hfuse (1 bytes):

Writing | ################################################## | 100% 0.02s

avrdude: 1 bytes of hfuse written
avrdude: verifying hfuse memory against 0x99:
avrdude: load data hfuse data from input file 0x99:
avrdude: input file 0x99 contains 1 bytes
avrdude: reading on-chip hfuse data:

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

avrdude: verifying ...
avrdude: 1 bytes of hfuse verified
avrdude: reading input file "0xff"
avrdude: writing lfuse (1 bytes):

Writing | ################################################## | 100% 0.02s

avrdude: 1 bytes of lfuse written
avrdude: verifying lfuse memory against 0xff:
avrdude: load data lfuse data from input file 0xff:
avrdude: input file 0xff contains 1 bytes
avrdude: reading on-chip lfuse data:

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

avrdude: verifying ...
avrdude: 1 bytes of lfuse verified

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

avrdude done.  Thank you.

 

But then, just as before, things appear bricked. No connection to flash bootloader or application is possible. Here is the output from any subsequent invocation of the same command (expect success in re-fusing)

"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avrdude" -CC:\Users\~\AppData\Local\Arduino15\packages\MegaCore\hardware\avr\2.0.1/avrdude.conf -v -patmega2560 -carduino -PCOM5 -b19200 -e -Ulock:w:0x3f:m -Uefuse:w:0xff:m -Uhfuse:w:0x99:m -Ulfuse:w:0xff:m 

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

         System wide configuration file is "C:\Users\~\AppData\Local\Arduino15\packages\MegaCore\hardware\avr\2.0.1/avrdude.conf"

         Using Port                    : COM5
         Using Programmer              : arduino
         Overriding Baud Rate          : 19200
         AVR Part                      : ATmega2560
         Chip Erase delay              : 9000 us
         PAGEL                         : PD7
         BS2                           : PA0
         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    10     8    0 no       4096    8      0  9000  9000 0x00 0x00
           flash         65    10   256    0 yes    262144  256   1024  4500  4500 0x00 0x00
           lfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           efuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           lock           0     0     0    0 no          1    0      0  9000  9000 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 : Arduino
         Description     : Arduino
         Hardware Version: 2
         Firmware Version: 1.18
         Topcard         : Unknown
         Vtarget         : 0.0 V
         Varef           : 0.0 V
         Oscillator      : Off
         SCK period      : 0.1 us

avrdude: AVR device initialized and ready to accept instructions

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

avrdude: Device signature = 0xffffff (retrying)

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

avrdude: Device signature = 0xffffff (retrying)

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

avrdude: Device signature = 0xffffff
avrdude: Yikes!  Invalid device signature.
         Double check connections and try again, or use -F to override
         this check.

avrdude done.  Thank you.

 

And then I have to once again apply the externally driven clock to recover the micro.

 

So my question is, what is wrong with these fuse settings? Or perhaps the problem is that my resonator is broken? I've beep tested to confirm it is soldered properly, but I suppose I could have damaged it when attaching it.

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

 

If you follow the link to engbedded above and put in the FF,9F,FF you are using I see:

 

 

On the whole I can't actually see much wrong with that as long as there IS a crystal close the chip across XTAL1/XTAL2 with 12-20pF capacitors on each leg to Gnd.

 

As there's no CKDIV8 then I would expect the CPU to clock at the same rate as the crystal frequency.

 

If you were able to recover the chip again then next time I might tick CKOUT (so low BF rather than FF) then probe pin E7 with a scope or frequency meter to verify that the chip is being clocked at the cyrstal frequency once the fuse programming is complete.

 

But other than that it looks like it should work.

 

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

I was using "FF, 99, FF". I tried with "FF, 9F, FF" too (didn't seem to matter either way - the changed bits seem to refer to bootsize and thus aren't clock related).

So, no luck thus far in trying out the other suggestions. I fused with CKOUT enabled but didn't see any signs of life on PE7. The distance between the clock and micro is short as well, maybe 20mm.

 

This is the datasheet for the resonator that I'm using: https://www.mouser.com/datasheet...

And the specific model of the resonator is "CSTCF16M0V53-R0". Following the part numbering scheme on page 3 of the datasheet, this model should have 15pF of built-in capacitance.

 

For a lark, I also manually soldered on extra 15pF caps from both leads to ground. No change in results there, though. I guess that actually just added another 15pF to each leg, parallel capacitors acting as they do.

 

At this point I suspect that the resonator is bad. I will try to replace it, run through all the tests again, and share my results.

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

Empty Set wrote:
"CSTCF16M0V53-R0"
fy : by Octopart, a typo that resolved to CSTCE...

 

 

"Dare to be naïve." - Buckminster Fuller

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

As an aside, I got burned by this once.  Apparently even Atmel (now Microchip) isn't consistent about the XTAL pins.

 

gchapman wrote:
XTAL2 then XTAL1, if need be, per a 11 step procedure :

 

I had a board layout with a mega3250 on it driven by an external clock signal fed into XTAL1.  It worked fine.  When we switched up to the claimed to be pin-compatible mega6450 for more code space it suddenly quit.  Fortunately we had a very sharp-eyed tech who could lift and swap the XTAL pins, and the big chip worked fine with an ext. clock on XTAL2.  S.

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

So, some good news and some bad news.

 

The good news is that after replacing the resonator with a new one, things seemed to work well! After burning bootloader and setting the fuses, I was able to then re-fuse immediately after with the external resonator. I also was able to use the ArduinoISP to program the application, and I observed that it appeared to be running off the resonator because it was executing more quickly. So, the initial problem was probably just that the first resonator had been damaged at some point.

 

The bad news is that, after fusing to use the external resonator, my USB controller (FT232) throws a fit. I followed this procedure:

 

ArduinoISP: Burn bootloader

ArduinoISP: Fuse micro to use external resonator (L:FF H:99 E:FF)

ArduinoISP: (Test re-fuse - works fine)

Remove ArduinoISP entirely from the circuit, re-connect FT232's DTR to ~Reset pin

FT232/AVRISPmkII: Try upload

 

The result is that the AVRISP fails every time (due to the "programmer is not responding" mode). I'm just getting started at looking into this failure so I haven't diagnosed much further - if anyone has ideas for the cause of this potential incompatibility let me know though.

 

As a side note - I can use the application with the resonator still by flashing application directly with ArduinoISP, but the idea of the FT232 in my circuit was to allow for easy reflash without needing all the wiring that hooking up an ArduinoISP entails. So ideally the resonator and FT232 would not conflict.

Last Edited: Mon. Feb 10, 2020 - 09:16 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 

Empty Set wrote:
... if anyone has ideas for the cause of this potential incompatibility let me know though.
Arduino bootloader goes via UART then USB CDC ACM (Windows virtual COM)

A resonator's accuracy will affect the baud rate error tolerance.

Some USB UART have precise enough baud rate adjustment and/or a fractional baud rate generator (FBRG)

mega2560 has a clock out (CLKO signal, 6 instances in the datasheet)

Alternatively, some logic analyzers have UART decoders; should be able to measure the mega2560's baud.

 

ATmega2560 - 8-bit AVR Microcontrollers

 

edit :

Well done on the fix!

 

edit2 :

Advanced Driver Options (FTDI, Microsoft Windows)

[page 17]

6.1 Aliasing Baud Rates

FTDI devices can support non-standard Baud rates.

...

 

"Dare to be naïve." - Buckminster Fuller

Last Edited: Mon. Feb 10, 2020 - 09:45 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

the resonator in an Arduino mega2560 rev 3 :

CSTCE16M0V53-R0

if correct, the baud is 57600 between the mega2560 and the mega16U2 (USB CDC ACM bridge to UART)

https://github.com/arduino/ArduinoCore-avr/blob/master/firmwares/atmegaxxu2/arduino-usbserial/Arduino-usbserial.c#L209

 

Arduino Mega 2560 Rev3 | Arduino Official Store

 

 

"Dare to be naïve." - Buckminster Fuller

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

Do you have a capacitor between DTR and RST?

#1 Hardware Problem? https://www.avrfreaks.net/forum/...

#2 Hardware Problem? Read AVR042.

#3 All grounds are not created equal

#4 Have you proved your chip is running at xxMHz?

#5 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand."

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

Empty Set wrote:

Remove ArduinoISP entirely from the circuit, re-connect FT232's DTR to ~Reset pin

FT232/AVRISPmkII: Try upload

 

The result is that the AVRISP fails every time...

 

Time to post your schematic.

#1 Hardware Problem? https://www.avrfreaks.net/forum/...

#2 Hardware Problem? Read AVR042.

#3 All grounds are not created equal

#4 Have you proved your chip is running at xxMHz?

#5 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand."

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


 

 

 

I did some more triage and first off, I should state that my procedure outlined above was a bit invalid. I noticed that bootloader/application seem to be lost when I run the avrdude fuse command, so running it after the bootloader is programmed and then hoping to immediately talk to the bootloader through the FT232 isn't a great way to go about things. Instead, I set the fuses to use the external clock, then burned bootloader, then removed the ArduinoISP, replaced the reset connection used by the FT232, and tried programming with it.

 

After fusing to use the external clock and with the CKOUT setting, I observe a clean 16MHz 0-5V wave on PE7 somewhere between a sine and a square, as expected.

 

The problem is that reprogramming doesn't work specifically with the external clock chosen over the FT232. I should note that in all other configurations everything works as expected. This helps rule out possible mistakes elsewhere in the circuit. To state it clearly then, the problem is just this last little piece of the "compatibility table":

 

Brian Fairchild wrote:
Do you have a capacitor between DTR and RST?

...

Time to post your schematic.

 

Yes. The schematic isn't much to write home about so I won't share the full thing, but the details of the FT232 circuit are relevant. The circuit is set up as described in this old thread I made: https://forum.arduino.cc/index.p...

(and of course, the fix discovered in that thread has been applied - so the reset pins of the two devices are separated, and DTR is connected to AVR !Reset with 0.1uF capacitance between).

 

gchapman wrote:

the resonator in an Arduino mega2560 rev 3 :

CSTCE16M0V53-R0

if correct, the baud is 57600 between the mega2560 and the mega16U2 (USB CDC ACM bridge to UART)

https://github.com/arduino/ArduinoCore-avr/blob/master/firmwares/atmegaxxu2/arduino-usbserial/Arduino-usbserial.c#L209

 

Arduino Mega 2560 Rev3 | Arduino Official Store

 

 

 

I'm not quite following your meaning in this or the other post. Do you mean that I should connect CKOUT (PE7) to some input of the FT232? I believe it is using its own internal clock right now and does successfully use it in this configuration when the Mega is fused to use its internal 8MHz oscillator. This implies that the clock speeds of the two devices work when they are independent of one another, so what's the justification for a change? Or perhaps you are suggesting I try something else?

 

Edit: Actually, an idea struck me, continuing from this line of thinking. Perhaps the settings used when burning the bootloader through the Arduino IDE matter in some capacity for its internal baud rate calculation. It may have something to do, then, with this clock selection menu which was the initial source of confusion for me in this thread.

 

Now for a bit finer control in my fusing, I actually just grabbed the two commands that ArduinoIDE executes when "Burn Bootloader" is selected and ran them on cmd. It seemed easier than fiddling with the settings files...

 

Those two commands were as follows (in order):

(Fuse)
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avrdude" -CC:\Users\~\AppData\Local\Arduino15\packages\MegaCore\hardware\avr\2.0.1/avrdude.conf -v -patmega2560 -carduino -PCOM5 -b19200 -e -Ulock:w:0x3f:m -Uefuse:w:0xff:m -Uhfuse:w:0x99:m -Ulfuse:w:0xbf:m

(Bootloader)
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avrdude" -CC:\Users\~\AppData\Local\Arduino15\packages\MegaCore\hardware\avr\2.0.1/avrdude.conf -v -patmega2560 -carduino -PCOM5 -b19200 -Uflash:w:C:\Users\~\AppData\Local\Arduino15\packages\MegaCore\hardware\avr\2.0.1/bootloaders/optiboot_flash/atmega2560/optiboot_flash_atmega2560_UART0_38400_8000000L.hex:i -Ulock:w:0x0f:m

Now that bottom command was copied from the IDE with the "8 MHz Internal" clock option selected, and I do see an optiboot hex with a clock rate seemingly called out ("8000000L"). So maybe I should try using a different optiboot hex? Maybe I'll try the "16 MHz External" option in the IDE and observe what command it runs. That's a bit strange to me as it's clear now that the "External" clock settings are not proper for my application, though. Any clarity on whether or not this could be the problem, and if so which flavor of bootloader I should use would be handy.

 

Last Edited: Tue. Feb 11, 2020 - 09:26 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Empty Set wrote:
Do you mean that I should connect CKOUT (PE7) to some input of the FT232?
No; fyi, some USB UART have a clock output to the MCU and likewise for mEDBG mega32U4.

CKOUT's frequency can be measured then mega2560's actual baud calculated.

Reasons :

  • verify resonator
  • if necessary, adjust FT232 baud (app via dll via sys where sys is the FT232 Windows driver)

Empty Set wrote:
so what's the justification for a change?
None

Empty Set wrote:
Or perhaps you are suggesting I try something else?
Yes

Empty Set wrote:
So maybe I should try using a different optiboot hex?
Bill's mega2560 Optiboot defaults to 16MHz.

Can't remember if Arduino mega2560 rev 3 bootloader is or isn't an instance of Optiboot.

edit2 : it's not

https://github.com/arduino/ArduinoCore-avr/tree/master/bootloaders/stk500v2

 


https://github.com/Optiboot/optiboot/blob/master/optiboot/bootloaders/optiboot/Makefile.2560#L14

 

edit : typo

 

"Dare to be naïve." - Buckminster Fuller

Last Edited: Tue. Feb 11, 2020 - 09:58 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

 

Solved! The fix was indeed to change around the Arduino settings to "16MHz External", which in turn changed the bootloader. Then I could just burn the bootloader using the ArduinoIDE "Burn Bootloader" command alone, surprisingly. I think the chip needs to be fused to work with the external resonator before trying to burn bootloader, however, which is likely why my first attempts didn't work.

 

Here was the output for standard "Burn Bootloader" with the "16MHz External" clock source option ticked. As you can see the optiboot hex changes to one that seems to be 16MHz default.

 

C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avrdude -CC:\Users\~\AppData\Local\Arduino15\packages\MegaCore\hardware\avr\2.0.1/avrdude.conf -v -patmega2560 -carduino -PCOM5 -b19200 -e -Ulock:w:0x3f:m -Uefuse:w:0xfd:m -Uhfuse:w:0xd6:m -Ulfuse:w:0xf7:m 

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

         System wide configuration file is "C:\Users\~\AppData\Local\Arduino15\packages\MegaCore\hardware\avr\2.0.1/avrdude.conf"

         Using Port                    : COM5
         Using Programmer              : arduino
         Overriding Baud Rate          : 19200
         AVR Part                      : ATmega2560
         Chip Erase delay              : 9000 us
         PAGEL                         : PD7
         BS2                           : PA0
         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    10     8    0 no       4096    8      0  9000  9000 0x00 0x00
           flash         65    10   256    0 yes    262144  256   1024  4500  4500 0x00 0x00
           lfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           efuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           lock           0     0     0    0 no          1    0      0  9000  9000 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 : Arduino
         Description     : Arduino
         Hardware Version: 2
         Firmware Version: 1.18
         Topcard         : Unknown
         Vtarget         : 0.0 V
         Varef           : 0.0 V
         Oscillator      : Off
         SCK period      : 0.1 us

avrdude: AVR device initialized and ready to accept instructions

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

avrdude: Device signature = 0x1e9801 (probably m2560)
avrdude: erasing chip
avrdude: reading input file "0x3f"
avrdude: writing lock (1 bytes):

Writing | ################################################## | 100% 0.01s

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.01s

avrdude: verifying ...
avrdude: 1 bytes of lock verified
avrdude: reading input file "0xfd"
avrdude: writing efuse (1 bytes):

Writing | ################################################## | 100% 0.01s

avrdude: 1 bytes of efuse written
avrdude: verifying efuse memory against 0xfd:
avrdude: load data efuse data from input file 0xfd:
avrdude: input file 0xfd contains 1 bytes
avrdude: reading on-chip efuse data:

C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avrdude -CC:\Users\~\AppData\Local\Arduino15\packages\MegaCore\hardware\avr\2.0.1/avrdude.conf -v -patmega2560 -carduino -PCOM5 -b19200 -Uflash:w:C:\Users\~\AppData\Local\Arduino15\packages\MegaCore\hardware\avr\2.0.1/bootloaders/optiboot_flash/atmega2560/optiboot_flash_atmega2560_UART0_115200_16000000L.hex:i -Ulock:w:0x0f:m 

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

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

avrdude: verifying ...
avrdude: 1 bytes of efuse verified
avrdude: reading input file "0xd6"
avrdude: writing hfuse (1 bytes):

Writing | ################################################## | 100% 0.01s

avrdude: 1 bytes of hfuse written
avrdude: verifying hfuse memory against 0xd6:
avrdude: load data hfuse data from input file 0xd6:
avrdude: input file 0xd6 contains 1 bytes
avrdude: reading on-chip hfuse data:

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

avrdude: verifying ...
avrdude: 1 bytes of hfuse verified
avrdude: reading input file "0xf7"
avrdude: writing lfuse (1 bytes):

Writing | ################################################## | 100% 0.01s

avrdude: 1 bytes of lfuse written
avrdude: verifying lfuse memory against 0xf7:
avrdude: load data lfuse data from input file 0xf7:
avrdude: input file 0xf7 contains 1 bytes
avrdude: reading on-chip lfuse data:

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

avrdude: verifying ...
avrdude: 1 bytes of lfuse verified

avrdude done.  Thank you.

         System wide configuration file is "C:\Users\~\AppData\Local\Arduino15\packages\MegaCore\hardware\avr\2.0.1/avrdude.conf"

         Using Port                    : COM5
         Using Programmer              : arduino
         Overriding Baud Rate          : 19200
         AVR Part                      : ATmega2560
         Chip Erase delay              : 9000 us
         PAGEL                         : PD7
         BS2                           : PA0
         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    10     8    0 no       4096    8      0  9000  9000 0x00 0x00
           flash         65    10   256    0 yes    262144  256   1024  4500  4500 0x00 0x00
           lfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           efuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           lock           0     0     0    0 no          1    0      0  9000  9000 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 : Arduino
         Description     : Arduino
         Hardware Version: 2
         Firmware Version: 1.18
         Topcard         : Unknown
         Vtarget         : 0.0 V
         Varef           : 0.0 V
         Oscillator      : Off
         SCK period      : 0.1 us

avrdude: AVR device initialized and ready to accept instructions

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

avrdude: Device signature = 0x1e9801 (probably m2560)
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 "C:\Users\~\AppData\Local\Arduino15\packages\MegaCore\hardware\avr\2.0.1/bootloaders/optiboot_flash/atmega2560/optiboot_flash_atmega2560_UART0_115200_16000000L.hex"
avrdude: writing flash (262144 bytes):

Writing | ################################################## | 100% -0.00s

avrdude: 262144 bytes of flash written
avrdude: verifying flash memory against C:\Users\~\AppData\Local\Arduino15\packages\MegaCore\hardware\avr\2.0.1/bootloaders/optiboot_flash/atmega2560/optiboot_flash_atmega2560_UART0_115200_16000000L.hex:
avrdude: load data flash data from input file C:\Users\~\AppData\Local\Arduino15\packages\MegaCore\hardware\avr\2.0.1/bootloaders/optiboot_flash/atmega2560/optiboot_flash_atmega2560_UART0_115200_16000000L.hex:
avrdude: input file C:\Users\~\AppData\Local\Arduino15\packages\MegaCore\hardware\avr\2.0.1/bootloaders/optiboot_flash/atmega2560/optiboot_flash_atmega2560_UART0_115200_16000000L.hex contains 262144 bytes
avrdude: reading on-chip flash data:

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

avrdude: verifying ...
avrdude: 262144 bytes of flash verified
avrdude: reading input file "0x0f"
avrdude: writing lock (1 bytes):

Writing | ################################################## | 100% 0.02s

avrdude: 1 bytes of lock written
avrdude: verifying lock memory against 0x0f:
avrdude: load data lock data from input file 0x0f:
avrdude: input file 0x0f contains 1 bytes
avrdude: reading on-chip lock data:

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

avrdude: verifying ...
avrdude: 1 bytes of lock verified

avrdude done.  Thank you.

 

However this also sets the fuses a bit differently (L:F7, H:D6, E:FD). I expected my Arduino to brick and need recovery via an external clock, but this time, strangely, the resonator appeared to work properly with these settings. I'm still a bit confused there because the fuse calculator gives this setting for those fuses:

 

But in any case it seemed to work, and I also tried with the fuse settings I'd used previously (L:BF, H:99, E:FF) and programming through the FT232 and application seemed to work appropriately. EDIT: Actually, it appears I was wrong about this. Everything is fine with ArduinoIDE's settings, and I verified that it is indeed 16MHz by changing those settings to also use CKOUT, but with my intended fuse settings I can do everything fine with the programmer (including flashing application), but the FT232 is still no good. Oh well, at this point I am fine with using Arduino's settings, but it is a bit confusing given the general knowledge about those settings. Hmm...

 

Thanks for getting me on the right track. The Makefile for the 2560 bootloader does indeed assume 16MHz, but it's a "?=" assignment so perhaps Arduino is defining 8MHz beforehand when I use the "Internal 8MHz" clock setting. That's my best guess for why I had this incompatibility.

 

Thanks all!

 

Last Edited: Thu. Feb 13, 2020 - 04:45 PM