Friday, March 16, 2018

Programming Atmel ATMEGA328-PU microcontroller using Arduino Mega board

The following method is used if ATMEGA328-PU microcontroller will be used with external oscillator 16 MHz. Before going on any steps, you should download Arduino IDE and install it. In this tutorial I am using Arduino IDE version 1.8.3

We want to use Arduino Mega 2560 as an ISP programmer for Atmel ATMEGA328-20PU DIP package microcontroller. To do this, we will do some steps for software and hardware.

A. Make the programmer

First: Software preparation:
[1] Before any wiring or creating any mess, connect Arduino Mega 2560 board to your PC using the USB cable

[2] Open Arduino IDE -> File -> Examples -> 11.Arduino ISP -> ArduinoISP.
By doing this "ArduinoISP" sketch will be opened. Keep the sketch as it is without any modification.

[3] Select Tools -> Board -> Arduino/Genuino Mega or Mega2560

[4] Select Tools -> Processor -> ATMEGA2560

[5] Select the correct COM port from Tools -> Port

[6] Select Sketch -> Upload

[7] By uploading the sketch, we have finished the software part.

Second: Hardware preparation:

[1] As many references said, we need 10 uF electrolytic capacitor (in my case I used a 33 uF capacitor which was available for me and it did the job). Connect the positive (long) lead of the capacitor to RESET pin of Arduino Mega 2560 and the short (negative) lead of the capacitor to GND pin of Arduino Mega. This capacitor is needed to disable resetting Arduino Mega.

[2] Now, we have turned our Arduino Mega 2560 to a programmer.


B. Burn the boot loader on target microcontroller

[1] Connect the following pins on ATMEGA328-PU microcontroller (target) to Arduino Mega board (which is used now as programmer):


Arduino Mega 2560 (programmer)
Pin name
ATMEGA328-PU (target)
Pin name
GND
GND
VCC
VCC
D10
RESET
D51 (MOSI)
D11
D50 (MISO)
D12
D52 (SCK)
D13




[2] Open Arduino IDE. Now, we will use the settings of the target microcontroller board.

[3] Tools -> Board -> Arduino Duemilanove or Decimilia

[4] Tools -> Processor -> ATmega328

[5] Tools -> Programmer -> Arduino as ISP

[6] Tools -> Burn boot loader

[7] Now, you have successfully turned your virgin ATMEGA328-20PU microcontroller to an Arduino-compatible microcontroller. Keep the previous wire connections and don't remove them because we will use them in the next step.



C. Upload your own sketch to your new microcontroller

[1] Create new sketch. I prefer using blinking LED sketch as a kick off

[2] Tools -> Board -> Arduino Duemilanove or Decimilia

[3] Tools -> Processor -> ATmega328

[4] Sketch -> Upload Using Programmer

[5] Congratulations. Your sketch is uploaded and your microcontroller is standalone.


References:

https://www.arduino.cc/en/Tutorial/ArduinoISP

http://www.instructables.com/id/How-to-use-Arduino-Mega-2560-as-Arduino-isp/

http://www.digitalstateone.net/2012/07/program-atmega328-standalone-with.html

https://www.gammon.com.au/forum/?id=11635&reply=2


Keywords:

Arduino boot loader for absolute beginner

Arduino boot loader tutorial

Arduino Mega 2560 as ISP programmer

Arduino Mega 2560 as AVR programmer

Arduino Mega 2560 as external programmer

Programming ATMEGA328-PU microcontroller using Arduino Mega

From Arduino board to compact board

From Arduino board to PCB board

Uploading boot loader to Atmel ATMEGA328-PU microcontroller

DIY Arduino-compatible micro

No comments:

Post a Comment