A small warning for users who ignore warnings and use an USBASP with an ATmega chip.
Since some users wanted to use an USBASP to flash the firmware, here is a warning:
Don't try without having some experience to recover an ATmega chip.
1. The USBASP with the original firmware has a bug that does not allow to flash >128 kb.
See this posting:
https://forum.arduino.cc/index.php?topic=363772.0
2. The USBASP is very unreliable. When something went wrong during step 1 (setting the fuses) or step 2 (flashing the firmware), in the worst case you cannot longer talk to the ATmega (doesn't matter what programmer you have).
I know that even when I give a warning in the manual, some people will still try (and some will have success), other might run into troubles.
To make it clear: When you have a patched USBASP flashing works in most(?) of the cases and even when the flash is interrupted no problems should occur. But when you are unlucky you run in the above described problem.
Here is a method how to recover the chip (this procedure will be also explained in the next manual update):
Basically, two types of errors are possible:
- By setting the fuses, the internal 1MHz clock is switched to the external crystal. If the ATmega2560 can no longer be addressed immediately afterwards, the crystal or one of the 22pF capacitors may be defective.
- If you started to flash the firmware after setting the fuses, then an error occurred and afterwards communication with the ATmega2560 is no longer possible, the fuses may have been affected.
If the AVRDUDE error message "initialization failed, rc=-1, double check connections..." appears: First of all, don't panic! It is almost impossible to lock yourself out of your ATmega2560 by software.
Presumably the fuses are in a state that the external crystal is not used and the internal 1 MHz are not available either (e.g. if all fuses have been deleted and an external clock is required), i.e. the chip lacks the clock source.
You can set the fuses again quite easily: All you have to do is apply a clock source to pin 34 (XTAL1) of the ATmega2560. It sounds more complicated than it is.
First you need a clock source. Here you can use an Arduino Uno or Mega, which you program with the following program:
Código: Seleccionar todo
#include <avr/io.h>
void setup() { }
void loop() {
DDRB = 0xFF;
while(1) {
PORTB ^= 0xFF;
}
}
This program generates a clock on pins 8 to 13 on the Arduino UNO and pins 10-13, 50-52 on the Arduino MEGA. If this program is loaded into the Arduino, the LED connected to pin 13 lights up only very weakly due to the constant on/off processes.
Now you connect pin 13 to XTAL1. The right leg of the 1 MOhm resistor below the crystal is ideal here. The connection must not have any wobbles and must not come into contact with the crystal.
Usually the crystal does not have to be unsoldered because the 5V clock of the Arduino is much stronger than the weak signal of the crystal. However, the firmware should not be fully programmed in this way, but rather the fuses should only be correctly programmed "quickly" so that the programming process can take place again without the external clock (with the existing crystal).
Once this connection has been established and the ISP programmer is connected, you can now try again to set the fuses (the programmer and port must be adjusted accordingly):
Código: Seleccionar todo
avrdude.exe -C"avrdude.conf" -B 4 -patmega2560 -cstk500 -PCOM5 -U lfuse:w:0xff:m -U hfuse:w:0xdf:m -U efuse:w:0xff:m
This process does not necessarily work the first time it is called, repeat it several times if necessary. Possibly, the crystal must also be removed.
If the fuses could now be set correctly, the firmware can be programmed.