1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

Help me rescue my ATmega32a?

Discussion in 'AVR' started by avrfan, Dec 17, 2016.

  1. avrfan

    avrfan New Member

    Joined:
    Dec 17, 2016
    Messages:
    6
    Likes:
    0
    I used a website to calculate the fuse settings for my ATmega32a but I missed one of the settings and have accidentally written fuses to expect an external clock instead of using it's internal oscillator as I had intended. (The fuses written are E: FF, H: D9, L: F0)
    I can no longer write new programs to it, nor rewrite the fuses.
    Besided the ATmega32a, I have avrdude, a USBtiny, and an arduino.
    I've tried programming a simple blink loop into the arduino to set a pin high for 1ms and low for 1ms, and connected that to XTAL1 on the ATmega32a as an external clock source while trying to rewrite the fuses but I couldn't get that to work. I'm not sure if I should have expected it to work.
    Is it possible to simulate an external clock with an arduino sufficiently well for a USBtiny to let me write my intended fuse settings? Do I need to supply any special arguments to avrdude?

    Here is what I see with the arduino connected to XTAL1
    Code (text):
     
     $ avrdude -c usbtiny -p atmega32 -vv

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

             System wide configuration file is "/etc/avrdude.conf"
             User configuration file is "/home/ac/.avrduderc"
             User configuration file does not exist or is not a regular file, skipping

             Using Port                    : usb
             Using Programmer              : usbtiny
    avrdude: usbdev_open(): Found USBtinyISP, bus:device: 003:011
             AVR Part                      : ATmega32
             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         4    10    64    0 no       1024    4      0  9000  9000 0xff 0xff
               flash         33     6    64    0 yes     32768  128    256  4500  4500 0xff 0xff
               lfuse          0     0     0    0 no          1    0      0  2000  2000 0x00 0x00
               hfuse          0     0     0    0 no          1    0      0  2000  2000 0x00 0x00
               lock           0     0     0    0 no          1    0      0  2000  2000 0x00 0x00
               signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00
               calibration    0     0     0    0 no          4    0      0     0     0 0x00 0x00

             Programmer Type : USBtiny
             Description     : USBtiny simple USB programmer, http://www.ladyada.net/make/usbtinyisp/
    avrdude: programmer operation not supported

    avrdude: Using SCK period of 10 usec
    CMD: [ac 53 00 00] [ac 50 00 00]
    CMD: [ac 53 00 00] [ff f3 00 00]
    avrdude: initialization failed, rc=-1
             Double check connections and try again, or use -F to override
             this check.


    avrdude done.  Thank you.
     
     
    Last edited: Dec 17, 2016
  2. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,157
    Likes:
    907
    Location:
    Rochdale UK
    Unless you have a HVPP (High Voltage Parallel Programming) programmer No..

    Which programmer are you using...
     
  3. avrfan

    avrfan New Member

    Joined:
    Dec 17, 2016
    Messages:
    6
    Likes:
    0
    I have a generic (ebay) usbtiny ISP, I don't have a HVPP unfortunately.
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. spec

    spec Well-Known Member Most Helpful Member

    Joined:
    Oct 27, 2015
    Messages:
    5,828
    Likes:
    709
    Location:
    Somerset UK GMT

    Hi avrfan,

    I know you haven't asked this, but why not just supply a physical clock to the ATmega32A- it is no big deal.:)

    spec
    2016_12_17_iss1_ATmega32A_Xtal_clock.png
    DATASHEET
    http://www.atmel.com/Images/Atmel-8155-8-bit-Microcontroller-AVR-ATmega32A_Datasheet.pdf
     
    Last edited: Dec 17, 2016
  6. avrfan

    avrfan New Member

    Joined:
    Dec 17, 2016
    Messages:
    6
    Likes:
    0
    I was trying to do that, in a way, using the arduino to supply the external clock pulses.
    If that's not a viable solution could you suggest which physical clock components I would need?
    And is there a guide anywhere I could follow?
     
  7. spec

    spec Well-Known Member Most Helpful Member

    Joined:
    Oct 27, 2015
    Messages:
    5,828
    Likes:
    709
    Location:
    Somerset UK GMT
    Our posts crossed. In the meantime I had updated my post #4 which may answer some of your questions.

    But if you need a list of specific components, can you let us know what clock frequency you would like to use. The clock frequency is a trade off between processing speed, power supply voltage, and current consumption.

    So if you can let us know what your power supply voltage is (the supply line must be decoupled by a 100nF (or over) ceramic capacitor connected close to the supply + and 0V pins on the AVR chip) and what your priorities are, one of us can post a definitive components list (three low-cost components).

    spec

    UPDATE 2016_12_17: I can't figure exactly what fuses you have blown- can you post a list using the fuse names and values described in the ATmega32A data sheet.
     
    Last edited: Dec 17, 2016
  8. avrfan

    avrfan New Member

    Joined:
    Dec 17, 2016
    Messages:
    6
    Likes:
    0
    I'd like to use the internal oscillator at 1MHz and I've been using a 5v supply.

    The fuses I've set were calculated using this page: http://www.engbedded.com/fusecalc
    This describes the clock setting that I've written to be :
    "Ext. Clock; Start-up time 6CK + 0ms; [CKSEL=0000 SUT=00]"
    whereas I should have chosen :
    "Int. RC Osc. 1MHz; Start-up time: 6CK + 64ms; [CKSEL=0001 SUT=10]"

    Otherwise, the other settings are
    BODEN=0
    BODLEVEL=1
    BOOTRST=0
    BOOTSZ=00
    EESAVE=0
    CKOPT=0
    SPIEN=0
    JTAGEN=0
    OCDEN=0

    It's a useful website - if you type in the fuse settings near the bottom of the page, it updates to tell you what they mean.


    Thanks for updating your reply, and thanks for the circuit diagram you've added. Are you showing how to add a crystal to XTAL1 and XTAL2? I thought that an external clock source and a crystal were different things.
    I tried connecting a 16MHz crystal (which is all I have) between XTAL1 and XTAL2 with capacitors as you've described but running the same command as above (avrdude -c usbtiny -p atmega32 -vv) is not successful.
     
  9. spec

    spec Well-Known Member Most Helpful Member

    Joined:
    Oct 27, 2015
    Messages:
    5,828
    Likes:
    709
    Location:
    Somerset UK GMT
    Hi avrfan,

    thanks for information. Yes, you are quite correct there are a number of non internal clock sources:
    (1) Xtal
    (2) Ceramic resonator
    (3) RC
    (4) External clock

    I had not read the ATmega32A data sheet fully or understood fully what you said in your OP.

    But generating an external clock (4) only requires the connection of one small package. If this approach is of any interest, just say and specify the frequency you require and what supply voltage you are using for your ATmega32A.

    spec
     
  10. Les Jones

    Les Jones Well-Known Member

    Joined:
    May 15, 2015
    Messages:
    1,445
    Likes:
    187
    Location:
    Lancashire UK
    Hi avrfan,
    The information on this web page may solve your problem.

    Les.
     
    • Like Like x 1
  11. avrfan

    avrfan New Member

    Joined:
    Dec 17, 2016
    Messages:
    6
    Likes:
    0
    Hi,

    To try to make things easy (?), let's say 5volt, 16MHz. I have a 16MHz crystal.

    The longer version is that I am interested in any approach that can allow me to rewrite the fuses with the limited kit that I've got, which rules out high voltage programming, but I do have a 16MHz crystal resonator, and I'm happy to use it and have the MC run at 16MHz.
    As I mentioned, I have a 5 volt supply, but I also have a 3.3volt supply that I could use too. My preference is 5V.
    Ideally I'd write the fuses to use the internal 1MHz oscillator but if I need to have the chip run at 16MHz as an intermediate step, then I'm happy to do it.
    I think that rules in options (3) and (4), and I thought both of those involved connecting to XTAL1 (and XTAL2), so I'm not sure whether option (1) is an entirely separate option that I'm unaware of, but I'm potentially interested in that. I don't think I have a ceramic resonator and don't have a high voltage supply or high voltage programmer, so those are both out.
     
  12. spec

    spec Well-Known Member Most Helpful Member

    Joined:
    Oct 27, 2015
    Messages:
    5,828
    Likes:
    709
    Location:
    Somerset UK GMT
    Hi avarfan,

    Perhaps I did not make it clear what I am suggesting which is to use an external clock permanently and leave the fuses as they are.:)

    None of the clock options (1) to (4) will allow the fuses to be reprogrammed.

    spec
     
    Last edited: Dec 17, 2016
  13. avrfan

    avrfan New Member

    Joined:
    Dec 17, 2016
    Messages:
    6
    Likes:
    0
    I see, I had not understood that. Thanks for clarifying.
    So it seems that for now my microcontroller is beyond rescuing, in which case I will resort to using a different microcontroller.
    Perhaps I will investigate a high voltage solution one day in the future to try to reset the fuses, but for now that is not an option available to me.
    Thanks for all your help
     
  14. spec

    spec Well-Known Member Most Helpful Member

    Joined:
    Oct 27, 2015
    Messages:
    5,828
    Likes:
    709
    Location:
    Somerset UK GMT
    No problem avrfan- sorry for the misunderstanding. I should have made my initial post clearer.:)

    Good luck with your AVR projects.

    spec
     

Share This Page