0

Program Atmega162 Bootloader with Arduino UNO
Moderators: altitude, adafruit_support_bill, adafruit, phono, hamburgers

Please be positive and constructive with your questions and comments.

Program Atmega162 Bootloader with Arduino UNO

by stinkleton on Mon Feb 10, 2020 8:14 pm

[Hopefully this works with other Arduinos as well -- see https://www.arduino.cc/en/tutorial/arduinoISP]

Parts: Arduino UNO, Atmega162, breadboard, breadboard wires, 10uf electrolytic cap, 16mhz xtal or resonator, two 22pf caps

Download the latest Arduino IDE and install. Connect your Arduino UNO with USB to PC.

1) Open the ArduinoISP firmware (in Examples) in Arduino IDE
2) Select the items in the Tools > Board and Serial Port menus that correspond to the board you are using as the programmer (not the board being programmed).
3) Upload the ArduinoISP sketch.
4) Disconnect Arduino from USB. Wire your Arduino UNO to the ATmega162 on a breadboard as follows:

UNO -> Atmega162
Miso (pin 12) -> Miso (pin 7)
Mosi (pin 11) -> Mosi (pin 6)
SS (pin 10) -> Reset (pin 9)
SCK (pin 13) -> SCK (pin 8)
+5v -> VCC (pin 40)
GND -> GND (pin 20)

16mhz Xtal or Resonator on Atmega pins 18+19 (middle pin of resonator to ground)

Each outer pin of Xtal or Resonator to a 22pf cap to gnd

10uf electrolytic capacitor between reset and gnd on UNO

Update Arduino files

pins_arduino.h needs to be saved to:
<arduino>\hardware\arduino\avr\variants\atmega162\pins_arduino.h

optiboot_atmega162.hex needs to be saved to:
<arduino>\hardware\arduino\avr\bootloaders\optiboot\optiboot_atmega162.hex

iom162.h needs to be saved to:
<arduino>\hardware\tools\avr\avr\include\avr\iom162.h
(This replaces the existing one. There is a bug which prevents code from compiling otherwise. Changing the file won't affect anything other than the Atmega162).

Add these lines to <arduino>\hardware\arduino\avr\boards.txt

##############################################################
atmega162.name= ATmega162
atmega162.upload.tool=avrdude
atmega162.upload.protocol=arduino
atmega162.upload.maximum_size=14336
atmega162.upload.speed=57600
atmega162.bootloader.tool=avrdude
atmega162.bootloader.low_fuses=0xFF
atmega162.bootloader.high_fuses=0xD8
atmega162.bootloader.extended_fuses=0xFB
atmega162.bootloader.file=optiboot/optiboot_atmega162.hex
atmega162.bootloader.unlock_bits=0x3F
atmega162.bootloader.lock_bits=0x0F
atmega162.build.mcu=atmega162
atmega162.build.f_cpu=16000000L
atmega162.build.core=arduino
atmega162.build.variant=atmega162
##############################################################

5) Reconnect the Arduino UNO to USB. Restart the Arduino IDE (close all open windows, and reopen).

6) Select "Tools->Board->'name from step 4' "

7) Select "Tools->Programmer->'Arduino as ISP' "

8) Click "Tools->'Burn Bootloader' "
Attachments
pins_arduino.h
(6.4 KiB) Downloaded 2 times
optiboot_atmega162.hex
(1.41 KiB) Downloaded 2 times
iom162.h
(20.38 KiB) Downloaded 3 times

stinkleton
 
Posts: 6
Joined: Sat Jun 29, 2019 10:22 am

Please be positive and constructive with your questions and comments.