Hello Forum,
I have some hassle with the flashing of an ATmega2560 over ISP. I think it has something to do with the platform.io params for uploading: I Use just the blink example extended with some serial output on Serial3 USART of the mega. I can compile and upload the program to an Arduino Mega2560 and to an custom board with this processor on it, but the program won’t start. It does not matter if i burn the bootloader on the mega or not (but i am searching for a solution without the bootloader). One strange side effect is that I get an error of avrdude from time to time, but when i erase the chip manually, I can flash it again:
avrdude: verifying …
avrdude: verification error, first mismatch at byte 0x010e
0x50 != 0x71
avrdude: verification error; content mismatch
I have to admit, that I tested a lot of parameters I found in several forum boards:
I think I can delete the clock delay param. This one I added because of the avrdude mismatch error. But it did not help.
The value for the HFuse is from this board. (I can’t find the topic at the moment, but it mantioned, that D9 is for starting the programm without the bootloader)
EFuse enables the BrownOut Detection
Lock results from the following avrdude message:
avrdude: WARNING: invalid value for unused bits in fuse “lock”, should be set to 1 according to datasheet
This behaviour is deprecated and will result in an error in future version
You probably want to use 0x3f instead of 0xff (double check with your datasheet first).
Can you verify that if you use the default fuses and the efuse and hfuse value for the Mega2560 preset on the Arduino ATMega2560 board, the LED works blinking?
lfuse = 0x42 and lock = 0xff as the default values for the ATMega2560.
Update:
When I now set the HFuse to D9, the Arduino starts blinking, but 16 times slower than it should.
Code : delay(1000);
Reality 16 sec. on - 16 sec off
with some fuse I pull the break of the Mega.
Will cause to enable the BOOTRST vector, so the Arduino framework might need this or it crashes after doing a reset after upload.
Probably crystal oscilator settings related in the lowfuse. Try burning back a LFUSE setting which corresponds to the ATMega board hardware, i.e. 16MHz external crystal. Maybe 0xFF? ("8.00 - ? MHz Oscillator, highest startup time and delay, no divide by 8)
Ok, this looks better now. The LED is blinking and the serial port is sending data, so the baud calculations should work now.
I still run into the avrdude mismatch error from time to time, but as long as I can fix this with the avrdude erase, I can cope with that.
I think I have to change the fuse back to the internal crystal for the custom board. Since it has no LED on, I first try my original Code with the Arduino and get back to the custom board then. Hopefully I will handle this the next hour.