This article explains how to program Atmel Atmega 328p with arduino. Following list of items are needed.
- Atmel Atmega 328p chip
- Arduino Uno board
- 16MHz Crystal Oscillator
- Two 22pF Capacitors
- 10 microF Capacitor
Note : 10microF capacitor is used between reset pin and ground pin in arduino to disable auto reset in arduino. First load ArduinoISP program to the arduino board. ArduinoISP program can be found in example codes.
- Slave Reset – 10
- MOSI – 11
- MISO – 12
- SCK – 13
Atmel Atmega 328p Pins
- Reset – 1
- MOSI – 17
- MISO – 18
- SCK – 19
Above arduino pins should be connected with the corresponding pins in the atmel chip.
Programming The Chip Using Makefile
1. Install AVR toolchain
2. To program an atmel chip, makefile and the C source file is needed. main.c file name is considered in makeFile. If you change the name of the source file, then makeFile is also needed to change accordingly.
- Makefile: https://gist.github.com/holachek/3304890
- main.c: https://gist.github.com/holachek/3304608 // sample C code for blinking LED
3. MakeFile configurations
Have to change following lines in makeFile according to the configurations of the atmel chip and circuit design.
FUSES = -U lfuse:w:0x7f:m -U hfuse:w:0xd9:m -U efuse:w:0xff:m
Note :Calculate FUSES line using the following link. Select Crystal Oscillator as external in Features section.
Fuse calculator: http://engbedded.com/fusecalc/
4. To program, use the command prompt and go to the file directory, Both makefile and the main.c file should be in the same directory.
Execute “make flash” command. If it is programmed correctly, the output will be as follows.
|Execute make flash command|