Site Tools


projects:3dprinting:anycubic_i3_mega:replacing_atmega2560

This is an old revision of the document!


Replace Atmega2560 at Trigorilla board

You need to make sure that you can flash the arduino bootloader again onto the chip.

For this you need an programmer like the AVR Dragon.

This is the wiring connection for the AVR Dragon to the Trigorilla ISP connector:

AVR Dragon ISP (pin) Trigorilla ISP connector (pin)
1: MISO 1: D50 (Mega2560 pin 22)
2: VTG 2: +5v
3: SCK 3: D52 (Mega2560 pin 20)
4: MOSI 4: D51 (Mega2560 pin 21)
5: RESET 5 RESET (Mega2560 pin 30)
6: GND 6: GND

To flash the bootloader, download and install avrdude:

Download avrdude

Install avrdude

gunzip -c avrdude-6.3.tar.gz | tar xf -
cd avrdude-6.0
./configure
make
su root -c 'make install'

udev rules

In /etc/udev/rules.d add (obviously as root user) the following file: 45-atmel.rules

# Atmel Corp. Dragon
ATTR{idVendor}=="03eb", ATTR{idProduct}=="2107", MODE="660", GROUP="dialout"

Then reload udev rules with:

sudo udevadm control --reload-rules && udevadm trigger

Flashing with avrdude

Steps and information below basically follow the description from here and here.

Download bootloader

A bootloader can be found in the arduino directory from where you downloaded the arduino IDE itself. The location for Arduino-1.8.5 is:

Original bootloader:

arduino-1.8.5/hardware/arduino/avr/bootloaders/stk500v2/Mega2560-prod-firmware-2011-06-29.hex

or the newer one that fixes the WDT and the !!! problems1):

arduino-1.8.5/hardware/arduino/avr/bootloaders/stk500v2/stk500boot_v2_mega2560.hex

0. Get Chip information

avrdude -p m2560 -P usb -c dragon_isp -v

1. Unlock fuses, erase, verify

The original command would be:

avrdude -p m2560 -c dragon_isp -P usb -Ulock:w:0x3F:m -Uefuse:w:0xFD:m -Uhfuse:w:0xD8:m -Ulfuse:w:0xFF:m -e -v

But this command will cause avrdude to show an error at the verification step2). To prevent this error, it is recommended to change this command into:

avrdude -p m2560 -c dragon_isp -P usb -Ulock:w:0xFF:m -Uefuse:w:0xFD:m -Uhfuse:w:0xD8:m -Ulfuse:w:0xFF:m -e -v

The reason is that only the lowest 3 bits from the lockbits are used. The other bits don't return any sensible value and causes avrdude to indicate an error. Ideally you would need to use a logical AND to filter for the lowest 3 bits.

2. Write the bootloader, set the lock fuse, verify

avrdude -p m2560 -c dragon_isp -P usb -Uflash:w:stk500boot_v2_mega2560.hex:i -Ulock:w:0x0f:m -v

Similarly as in step 2, to prevent an error with the fuse setting at the verification step, change this command in:

avrdude -p m2560 -c dragon_isp -P usb -Uflash:w:stk500boot_v2_mega2560.hex:i -Ulock:w:0xcf:m -v

Problems

verification error, first mismatch at byte 0x0000

If you get an error like the following with avrdude:

...
Reading | ################################################## | 100% 0.05s
 
avrdude: verifying ...
avrdude: verification error, first mismatch at byte 0x0000
         0xcf != 0x0f
avrdude: verification error; content mismatch
...

You may have to change the fuse setting verification step3). See above for the change.

Further information

projects/3dprinting/anycubic_i3_mega/replacing_atmega2560.1584004313.txt.gz · Last modified: 2020/03/12 10:11 by admin