Bricked atmega 1284 with avrdude! Can it be saved? - Page 1
Forum section: electronics / beginners

author: belzrebuth
author_rank: Frequent Contributor
timestamp: October 13, 2022, 04:39:02 pm
content: Hi all,I bricked an atmega 1284 (non p version) by runningQuoteThen I can't communicate with it.I get --> avrdude: Device signature = 0x000000I know I shouldn't have pressed Ctrl+C but it seemed stuck trying to repair the fuses.I have a TL866A so I tried reviving the chip by blank programming it to reset the fuses to their original state but it doesn't work either I still get an ID of 0x000000.The chip is the SMD version so I can't just plug it in the 40P port of the TL866; I've used the ICSP port to try to unbrick it.I could buy an adaptor if it's necessary for the chip to be in the 40P port to be restored.Can this chip be saved? I've succesfully restored the fuses of many atmegas using the TL866 I don't know what I'm doing wrong this time.

author: ledtester
author_rank: Super Contributor
timestamp: October 13, 2022, 05:30:52 pm
content: An lfuse setting of 0x62 suggests you're using the internal oscillator for the system clock:http://eleccelerator.com/fusecalc/fusecalc.php?chip=atmega1284p&LOW=62&HIGH=99&EXTENDED=FF&LOCKBIT=FFIs that right or are you using a crystal for the system clock?If the lfuse really got set to 0x00 the chip would be expecting an external clock source and that would be needed to program the chip.Does the TL866 supply that clock or can it be configured to supply that clock?Note the ICSP programming speed must be <= 1/4 the system clock.An easy way to provide a clock source to the chip would be to use another microcontroller.

author: belzrebuth
author_rank: Frequent Contributor
timestamp: October 13, 2022, 06:14:27 pm
content: When the device used its internal clock it got recognised by avrdude fine without any ext clock.It's only after I got it messed up that it stopped responding.A low fuse set at 0x00 suggests that I should use an EXT clock as per the attachment.I checked it with an AVR fuse calculator and took a screenshot of what the lfuse means but I don't understand what clock frequency I should use with that setting.Of course I've tried with 20 and 16 MHz crystals I had lying around but I didn't get it to respond.I have other MCUs and I believe I also have 8MHz and 4MHz crystals as well.I also have an Arduino I could use as a programmer.I don't think the TL866 can supply a clock, correct me If I'm wrong.I recently set an ATMEGA8 to use EXT clock and it stopped communicating but I was very easily able to restore it with the TL866 just be resetting the fuses.I don't know why I'm not able to do this with the 1284? Perhaps I should use an adapter to place it in the 40P port? Or it doesn't matter?Is there any foolproof way to just reset everything?

author: ledtester
author_rank: Super Contributor
timestamp: October 13, 2022, 06:37:44 pm
content: I would proceed on the assumption that lfuse is set to 0x00 and apply an external clock signal (I believe to XTAL1).Then try ICSP programming with a speed < 1/32 of the applied clock. This takes into account the divide-by-8 prescaler that is set by the lfuse setting.Quote from: belzrebuth on October 13, 2022, 06:14:27 pmWhen you plugged the 1284 into the TL866 did you connect the XTAL1 pin?

author: belzrebuth
author_rank: Frequent Contributor
timestamp: October 13, 2022, 06:49:47 pm
content: Do you know what frequency should the clock signal should be?Provided that the lfuse is 0x00?I read that the "6CK" is 128KHz?I don't think I have a 128KHz XTAL only 32,768Hz..Because I've already tried 16 and 20MHz and the usbtiny can't see the chip via avrdude.I think I first need to find a way to see the chip and then I could try reducing the programming speed to 1/8.I also think that the TL866 does serial programming thru its ICSP port and parallel programming via the 40P socket port.So that may be the reason that I can't just reset it, because reseting it would require a high voltage reset and parallel programming..

author: belzrebuth
author_rank: Frequent Contributor
timestamp: October 13, 2022, 06:55:50 pm
content: Quote from: ledtester on October 13, 2022, 06:37:44 pmI didn't plug it directly I'm only using the ICSP port of the TL866 because the chip is a TQFP-44 package and is already soldered to an otherwise empty PCB.That PCB has a 6pin header for programming the chip.I've tried both with a XTAL installed and without but I'm not sure about the frequency.The PCB has a place for a 20MHz crystal and 2* 18pF capacitors. I tried both 20MHz and 16MHz.avrdude returns when I try the board with a usbtiny.Code:avrdude: initialization failed, rc=-1Double check connections and try again, or use -F to overridethis check.if the chip is still alive which I believe it's maybe a matter of providing the correct CLK signal for a programmer to be able to see it..

author: ledtester
author_rank: Super Contributor
timestamp: October 13, 2022, 08:43:01 pm
content: You need the programming speed of the ICSP to be less than your system clock/32.Try using the option "-B 8" with avrdude. This sets the ICSP bit rate to 125 KHz which will be slow but should work with crystals > 4 MHz.Quote

author: Kleinstein
author_rank: Super Contributor
timestamp: October 13, 2022, 09:21:52 pm
content: The most common way to brick an AVR is by setting the fuses to that is expects an external excillator. In this case one has to provide an external clock to the XTAL1 pin, not just and external resonator.The external clock also works when the µC is set to a different clock option (e.g. external cystal or ceramic resonator) - not sure of it is OK to still have a cystal present, but probably it work if not resonant.The exact clock speed does not mater. If slow, the programmer has to be slowed down. Worst case the div 8 fuse is "active" and the clock seen by the µC is only 1/8 of the external clock. So one may have to use a relatively slow speed setting.

author: belzrebuth
author_rank: Frequent Contributor
timestamp: October 13, 2022, 11:37:54 pm
content: Shouldn't avrdude see the MCU if any clock source was available?Or I specifically need to to slow the programmer down in order for the programmer to see the chip?

author: ledtester
author_rank: Super Contributor
timestamp: October 13, 2022, 11:58:13 pm
content: Quote from: belzrebuth on October 13, 2022, 11:37:54 pmThe way the programmer "sees" the chip is by sending a message over SPI and sees if it gets a valid response.If the SPI speed is too fast for the mcu it will not get a valid response back.

author: james_s
author_rank: Super Contributor
timestamp: October 14, 2022, 12:16:15 am
content: IMHO the biggest flaw of the AVR chips has always been the fact that the clock source is needed for programming making it easy to brick. I've done it a few times myself and sometimes it's a real pain to hook up a clock source to get it to do something. The programmer really ought to provide the clock needed at least to configure the onboard oscillator.

author: ledtester
author_rank: Super Contributor
timestamp: October 14, 2022, 12:22:28 am
content: It is also possible that the high fuse value was mangled and serial programming was disabled.In that case you'll have to resort to high-voltage programming.

author: belzrebuth
author_rank: Frequent Contributor
timestamp: October 14, 2022, 01:09:21 am
content: Code:avrdude -c usbtiny -p m1284p -F -B 8 -U flash:r:merged.hex:iavrdude: initialization failed, rc=-1avrdude: AVR device initialized and ready to accept instructionsavrdude: Device signature = 0x000000avrdude: Yikes! Invalid device signature.avrdude: Expected signature for ATMEGA1284P is 1E 97 05avrdude done. Thank you.That is with 20MHz crystal attached.The -F is needed for the 1284 (non-P) to be "recognised".I may indeed have to resort to high-voltage programming which I guess needs a DIP adapter for the smd chip.I don't have such an adapter, making a PCB and ordering it will take some time.If not many connections are required I can get away with soldering a few cables from the chip to go directly to the TL866 socket..

author: alm
author_rank: Super Contributor
timestamp: October 14, 2022, 01:54:16 am
content: If the clock selection fuses are set to low frequency crystal, then the standard recommendation of feeding a few MHz square wave into XTAL1 may not work. Try hooking up a 32,768 kHz watch crystal per datasheet and see if that helps.Try a very low programming speed down to the kHz.

author: sleemanj
author_rank: Super Contributor
timestamp: October 14, 2022, 01:56:32 am
content: You were reading from it, not writing to it, it read ok then it went away, there is no reason that the fuses should have changed.0x00 (fuses, signature) is indicative of a complete failure to communicate.If it was me, what I would be looking at is a lot more fundamental than a fuse or clock issue. Check your wiring, voltages, and reset.

author: Kleinstein
author_rank: Super Contributor
timestamp: October 14, 2022, 06:27:36 am
content: The error message from the start indeed indicates a problem with the communication. It is unlikely that the fuses are changed, though with unreliable communication it is possible by accident.So it is really about checking the supply (e.g. all pins connected, decoupling caps ?, suitable voltage (e.g. same as the programmer)). Too long cables can also be an issue (especially ringing on the clock line).Even the low speed crystl setting has a good chance to work with an external clock, especially if not too fast. The main point for the low frequency is a weak drive strength, not to overdrive and possibly damage a 32 kHz crystal.Providing a clock signal (e.g. 1 MHz) would indeed be a good addition to a programmer.

author: belzrebuth
author_rank: Frequent Contributor
timestamp: October 14, 2022, 10:19:03 am
content: Cables are okay.I buzzed the connections and they all check out.I would normally buy another chip and make a converter board to save this one but I can't buy another at the moment they re all out of stock for months now.What connections are required for high voltage programming?!I could solder 30awg wire from the chip to a couple of 20pin single headers to fit the test socket on my TL866 if not all the pins are needed.

author: Mechatrommer
author_rank: Super Contributor
timestamp: October 14, 2022, 10:41:40 am
content: you can also use function generator to feed as external clock, feed at low voltage swing maybe 1Vpp (0-1V square or sine) and then you can play at the ext clock frequency end if its too difficult to configure from programmer end. i think i recovered one bricked AVR this way.

author: belzrebuth
author_rank: Frequent Contributor
timestamp: October 14, 2022, 11:04:20 am
content: I have a function generator so I could do that.But I'm a bit unsure of the pins and whether I should keep the 18pF capacitors.I guess the capacitors should be removed since there's no loading required, the signal will be accurate enough on its ownXtal 1 should be signal and XTAL 2 should be GND?My DG1022z is grounded by default so I think the laptop and programmer should be floating.(on battery mode)Is that correct?

author: alm
author_rank: Super Contributor
timestamp: October 14, 2022, 11:47:56 am
content: Yes, you would remove the capacitors and crystal. Connect the function generator to XTAL1, and the function generator ground to the board ground. Don't connect anything to XTAL2. See figure 9-4 from page 46 of thedatasheet:There shouldn't be a problem with both the programmer and function generator being grounded. There's a small chance of ground loops inducing noise, but I don't think that would be a problem for a 3.3-5V digital system. Just make sure both grounds are connected to the same node in the circuit

author: belzrebuth
author_rank: Frequent Contributor
timestamp: October 14, 2022, 01:04:49 pm
content: Thank you!I will try that later when I'm home and post back.

author: Ian.M
author_rank: Super Contributor
timestamp: October 14, 2022, 02:06:59 pm
content: Remove the crystal, or desolder one pin if its through hole. The caps can stay as the function generator should easily be able to drive a few tens of pF.

author: belzrebuth
author_rank: Frequent Contributor
timestamp: October 14, 2022, 03:18:24 pm
content: Okay 1Vpp 128KHz square at pin7 and GND of the fgen to GND of the IC.Same output on the avrdude console.Code:avrdude -c usbtiny -p m1284p -Favrdude: initialization failed, rc=-1avrdude: AVR device initialized and ready to accept instructionsavrdude: Device signature = 0x000000avrdude: Yikes! Invalid device signature.avrdude: Expected signature for ATMEGA1284P is 1E 97 05avrdude done. Thank you.Code:avrdude -c usbtiny -p m1284p -F -B 8avrdude: initialization failed, rc=-1avrdude: AVR device initialized and ready to accept instructionsavrdude: Device signature = 0x000000avrdude: Yikes! Invalid device signature.avrdude: Expected signature for ATMEGA1284P is 1E 97 05avrdude done. Thank you.I also tried 32KHz and -B 4/ 8 options..I don't know what else to do..

author: Mechatrommer
author_rank: Super Contributor
timestamp: October 14, 2022, 03:34:11 pm
content: if the RESETDISABLE fuse is set, then you need high voltage programmer, this thread might give some tips...https://www.avrfreaks.net/forum/reset-disable-preventing-serial-programmingwith this anomaly, i'll bring up my ISP Mk2 programmer instead of avrdude. your general purpose programmer TL866A + Func Gen may give some more light if you dont have Mk2.. set ISP freq to much slower KHz while clock is in MHz range. disconnect everything from the MCU except programmer, fg (clock) and power supply. ymmv.

author: ledtester
author_rank: Super Contributor
timestamp: October 14, 2022, 03:44:58 pm
content: Quote from: belzrebuth on October 14, 2022, 03:18:24 pmThe -B option is the period of an SPI clock cycle in microseconds. A system clock of 32 KHz has a period of 31 microseconds. The SPI clock period needs to be 4 times that.Try something like "-B 300". It'll be slow but has a better chance of working.

author: belzrebuth
author_rank: Frequent Contributor
timestamp: October 14, 2022, 04:04:19 pm
content: I didn't know about -B option, regardless I still get the same response even with -B 300..Quote from: Mechatrommer on October 14, 2022, 03:34:11 pmI have a ISP Mk2 as well. I think it only works with atmel studio tho, I need to change the driver for it or flash it with another firmware.I used to have the mk2 for the atmel studio (university stuff) and the usbtiny for avrdude (home stuff) and I ended up only using the usbtiny for everything.I can find my MK2 if needed no problem.How do I change the ISP frequency of TL866, I don't see any option for it.

author: Mechatrommer
author_rank: Super Contributor
timestamp: October 14, 2022, 04:32:06 pm
content: Quote from: belzrebuth on October 14, 2022, 04:04:19 pmi'm not sure with your tools. but avr (now microchip) studio we can change isp frequency. i have newer TL866II, but i only used it once to read a flash's memory, nothing more. what i know is different adapter is needed to read/progam avr mcu. if all tools/aspects are tried and still failed, maybe its the RESETDISABLE fuse, beyond that, the mcu maybe fried and the fix is$8... ymmv

author: belzrebuth
author_rank: Frequent Contributor
timestamp: October 14, 2022, 05:06:49 pm
content: It's not the $8; it's that they're always backordered and the delivery dates are insane..I'll see what I can do; I believe it's only a matter of high voltage programming.It's not my first fail with AVR devices; I've goofed up the fuses a lot of times in the past and it always a DIP package so I revived it without ever messing with all of this.It was just a matter of plugging it into the TL866 and by hitting "program" with the check ID option unchecked; the fuses were restored and the chip was back to action.I never tried that procedure with ICSP but apparently it doesn't work.That's why I'm asking which pins are necessary to perform a high voltage parallel programming; maybe I could just bite the bullet and solder 40 cables in a couple of 20pin headers and be done with it.More often than not time spent just talking about something is more than the actual time to do it..

author: belzrebuth
author_rank: Frequent Contributor
timestamp: October 14, 2022, 05:47:32 pm
content: An update:I just included -B 123 without any external clock and got this:Code:avrdude -c usbtiny -p m1284p -F -B 123avrdude: AVR device initialized and ready to accept instructionsReading | ################################################## | 100% 0.07savrdude: Device signature = 0x1e9706avrdude: Expected signature for ATMEGA1284P is 1E 97 05avrdude: safemode: Fuses OKavrdude done. Thank you.

author: belzrebuth
author_rank: Frequent Contributor
timestamp: October 14, 2022, 08:04:29 pm
content: The chip now works even with a 20MHz I don't know what was causing this.I consistenly get this error though :avrdude: verifying ...avrdude: verification error, first mismatch at byte 0x100000xff != 0xb2avrdude: verification error; content mismatchThe error stays the same even with a different firmware so I hope it's not a hardware problem...edit: I tried burning a MightyCore bootloader and it works so the chip is okay. There might be something wrong with the firmware I'm trying to upload.