Compilation of C program and flashing the ATmega328p microcontroller using free Linux tools
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Step 1. Create a .bin file | |
# Arguments at the end: destination_bin_file.bin c_program.c | |
avr-gcc -Wall -g -Os -mmcu=atmega328p -o main.bin main.c | |
# Step 1.1 (optional) look up the .bin file | |
avr-size -C main.bin | |
# Step 2. Conversion of .bin file to .hex file | |
avr-objcopy -j .text -j .data -O ihex main.bin main.hex |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Using GPIO (e.g. Raspberry Pi) | |
# Configuration and wiring for Raspberry Pi: | |
# http://ozzmaker.com/program-avr-using-raspberry-pi-gpio/ | |
sudo avrdude -p atmega328p -c linuxgpio -U flash:w:main.hex:i -F | |
# Using ISP programmer (e.g. Pololu USB AVR Programmer) | |
# Please note that the name of device /dev/ttyACM0 might differ. | |
# My suggestion is to check contents of /dev directory before and after plugging of programmer. | |
sudo avrdude -c avrisp2 -p atmega328p -P /dev/ttyACM0 -U flash:w:main.hex:i -F | |
# More commands | |
# To verify the configuration: | |
sudo avrdude -c avrisp2 -p atmega328p -P /dev/ttyACM0 -v | |
# Reading contents of the chip: | |
sudo avrdude -c avrisp2 -p atmega328p -P /dev/ttyACM0 -U flash:r:output_file.bin:r |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2232HIO = FT2232H based generic programmer [/etc/avrdude.conf:412] | |
4232h = FT4232H based generic programmer [/etc/avrdude.conf:440] | |
89isp = Atmel at89isp cable [/etc/avrdude.conf:1369] | |
abcmini = ABCmini Board, aka Dick Smith HOTCHIP [/etc/avrdude.conf:1268] | |
alf = Nightshade ALF-PgmAVR, http://nightshade.homeip.net/ [/etc/avrdude.conf:1228] | |
arduino = Arduino [/etc/avrdude.conf:360] | |
arduino-ft232r = Arduino: FT232R connected to ISP [/etc/avrdude.conf:764] | |
atisp = AT-ISP V1.1 programming cable for AVR-SDK1 from <http://micro-research.co.th/> [/etc/avrdude.conf:1324] | |
atmelice = Atmel-ICE (ARM/AVR) in JTAG mode [/etc/avrdude.conf:1114] | |
atmelice_dw = Atmel-ICE (ARM/AVR) in debugWIRE mode [/etc/avrdude.conf:1130] | |
atmelice_isp = Atmel-ICE (ARM/AVR) in ISP mode [/etc/avrdude.conf:1138] | |
atmelice_pdi = Atmel-ICE (ARM/AVR) in PDI mode [/etc/avrdude.conf:1122] | |
avr109 = Atmel AppNote AVR109 Boot Loader [/etc/avrdude.conf:885] | |
avr910 = Atmel Low Cost Serial Programmer [/etc/avrdude.conf:721] | |
avr911 = Atmel AppNote AVR911 AVROSP [/etc/avrdude.conf:892] | |
avrftdi = FT2232D based generic programmer [/etc/avrdude.conf:386] | |
avrisp = Atmel AVR ISP [/etc/avrdude.conf:608] | |
avrisp2 = Atmel AVR ISP mkII [/etc/avrdude.conf:628] | |
avrispmkII = Atmel AVR ISP mkII [/etc/avrdude.conf:622] | |
avrispv2 = Atmel AVR ISP V2 [/etc/avrdude.conf:615] | |
bascom = Bascom SAMPLE programming cable [/etc/avrdude.conf:1222] | |
blaster = Altera ByteBlaster [/etc/avrdude.conf:1346] | |
bsd = Brian Dean's Programmer, http://www.bsdhome.com/avrdude/ [/etc/avrdude.conf:1177] | |
buspirate = The Bus Pirate [/etc/avrdude.conf:633] | |
buspirate_bb = The Bus Pirate (bitbang interface, supports TPI) [/etc/avrdude.conf:640] | |
butterfly = Atmel Butterfly Development Board [/etc/avrdude.conf:878] | |
butterfly_mk = Mikrokopter.de Butterfly [/etc/avrdude.conf:906] | |
bwmega = BitWizard ftdi_atmega builtin programmer [/etc/avrdude.conf:751] | |
C232HM = FT232H based module from FTDI and Glyn.com.au [/etc/avrdude.conf:509] | |
c2n232i = serial port banging, reset=dtr sck=!rts mosi=!txd miso=!cts [/etc/avrdude.conf:1474] | |
dapa = Direct AVR Parallel Access cable [/etc/avrdude.conf:1312] | |
dasa = serial port banging, reset=rts sck=dtr mosi=txd miso=cts [/etc/avrdude.conf:1446] | |
dasa3 = serial port banging, reset=!dtr sck=rts mosi=txd miso=cts [/etc/avrdude.conf:1460] | |
diecimila = alias for arduino-ft232r [/etc/avrdude.conf:775] | |
dragon_dw = Atmel AVR Dragon in debugWire mode [/etc/avrdude.conf:1041] | |
dragon_hvsp = Atmel AVR Dragon in HVSP mode [/etc/avrdude.conf:1032] | |
dragon_isp = Atmel AVR Dragon in ISP mode [/etc/avrdude.conf:1014] | |
dragon_jtag = Atmel AVR Dragon in JTAG mode [/etc/avrdude.conf:1005] | |
dragon_pdi = Atmel AVR Dragon in PDI mode [/etc/avrdude.conf:1050] | |
dragon_pp = Atmel AVR Dragon in PP mode [/etc/avrdude.conf:1023] | |
dt006 = Dontronics DT006 [/etc/avrdude.conf:1212] | |
ere-isp-avr = ERE ISP-AVR <http://www.ere.co.th/download/sch050713.pdf> [/etc/avrdude.conf:1335] | |
flip1 = FLIP USB DFU protocol version 1 (doc7618) [/etc/avrdude.conf:1161] | |
flip2 = FLIP USB DFU protocol version 2 (AVR4023) [/etc/avrdude.conf:1168] | |
frank-stk200 = Frank STK200 [/etc/avrdude.conf:1359] | |
ft232r = FT232R Synchronous BitBang [/etc/avrdude.conf:739] | |
ft245r = FT245R Synchronous BitBang [/etc/avrdude.conf:728] | |
futurlec = Futurlec.com programming cable. [/etc/avrdude.conf:1279] | |
jtag1 = Atmel JTAG ICE (mkI) [/etc/avrdude.conf:919] | |
jtag1slow = Atmel JTAG ICE (mkI) [/etc/avrdude.conf:924] | |
jtag2 = Atmel JTAG ICE mkII [/etc/avrdude.conf:954] | |
jtag2avr32 = Atmel JTAG ICE mkII im AVR32 mode [/etc/avrdude.conf:987] | |
jtag2dw = Atmel JTAG ICE mkII in debugWire mode [/etc/avrdude.conf:969] | |
jtag2fast = Atmel JTAG ICE mkII [/etc/avrdude.conf:948] | |
jtag2isp = Atmel JTAG ICE mkII in ISP mode [/etc/avrdude.conf:960] | |
jtag2pdi = Atmel JTAG ICE mkII PDI mode [/etc/avrdude.conf:996] | |
jtag2slow = Atmel JTAG ICE mkII [/etc/avrdude.conf:943] | |
jtag3 = Atmel AVR JTAGICE3 in JTAG mode [/etc/avrdude.conf:1058] | |
jtag3dw = Atmel AVR JTAGICE3 in debugWIRE mode [/etc/avrdude.conf:1074] | |
jtag3isp = Atmel AVR JTAGICE3 in ISP mode [/etc/avrdude.conf:1082] | |
jtag3pdi = Atmel AVR JTAGICE3 in PDI mode [/etc/avrdude.conf:1066] | |
jtagkey = Amontec JTAGKey, JTAGKey-Tiny and JTAGKey2 [/etc/avrdude.conf:447] | |
jtagmkI = Atmel JTAG ICE (mkI) [/etc/avrdude.conf:911] | |
jtagmkII = Atmel JTAG ICE mkII [/etc/avrdude.conf:935] | |
jtagmkII_avr32 = Atmel JTAG ICE mkII im AVR32 mode [/etc/avrdude.conf:978] | |
lm3s811 = Luminary Micro LM3S811 Eval Board (Rev. A) [/etc/avrdude.conf:570] | |
mib510 = Crossbow MIB510 programming board [/etc/avrdude.conf:672] | |
mkbutterfly = Mikrokopter.de Butterfly [/etc/avrdude.conf:900] | |
nibobee = NIBObee [/etc/avrdude.conf:847] | |
o-link = O-Link, OpenJTAG from www.100ask.net [/etc/avrdude.conf:541] | |
openmoko = Openmoko debug board (v3) [/etc/avrdude.conf:552] | |
pavr = Jason Kyle's pAVR Serial Programmer [/etc/avrdude.conf:1147] | |
pickit2 = MicroChip's PICkit2 Programmer [/etc/avrdude.conf:1154] | |
picoweb = Picoweb Programming Cable, http://www.picoweb.net/ [/etc/avrdude.conf:1257] | |
pony-stk200 = Pony Prog STK200 [/etc/avrdude.conf:1205] | |
ponyser = design ponyprog serial, reset=!txd sck=rts mosi=dtr miso=cts [/etc/avrdude.conf:1424] | |
siprog = Lancos SI-Prog <http://www.lancos.com/siprogsch.html> [/etc/avrdude.conf:1437] | |
sp12 = Steve Bolt's Programmer [/etc/avrdude.conf:1245] | |
stk200 = STK200 [/etc/avrdude.conf:1189] | |
stk500 = Atmel STK500 [/etc/avrdude.conf:658] | |
stk500hvsp = Atmel STK500 V2 in high-voltage serial programming mode [/etc/avrdude.conf:693] | |
stk500pp = Atmel STK500 V2 in parallel programming mode [/etc/avrdude.conf:686] | |
stk500v1 = Atmel STK500 Version 1.x firmware [/etc/avrdude.conf:665] | |
stk500v2 = Atmel STK500 Version 2.x firmware [/etc/avrdude.conf:679] | |
stk600 = Atmel STK600 [/etc/avrdude.conf:700] | |
stk600hvsp = Atmel STK600 in high-voltage serial programming mode [/etc/avrdude.conf:714] | |
stk600pp = Atmel STK600 in parallel programming mode [/etc/avrdude.conf:707] | |
ttl232r = FTDI TTL232R-5V with ICSP adapter [/etc/avrdude.conf:811] | |
tumpa = TIAO USB Multi-Protocol Adapter [/etc/avrdude.conf:591] | |
UM232H = FT232H based module from FTDI and Glyn.com.au [/etc/avrdude.conf:482] | |
uncompatino = uncompatino with all pairs of pins shorted [/etc/avrdude.conf:787] | |
usbasp = USBasp, http://www.fischl.de/usbasp/ [/etc/avrdude.conf:822] | |
usbasp-clone = Any usbasp clone with correct VID/PID [/etc/avrdude.conf:858] | |
usbtiny = USBtiny simple USB programmer, http://www.ladyada.net/make/usbtiny | |
/ [/etc/avrdude.conf:869] | |
wiring = Wiring [/etc/avrdude.conf:353] | |
xil = Xilinx JTAG cable [/etc/avrdude.conf:1298] | |
xplainedmini = Atmel AVR XplainedMini in ISP mode [/etc/avrdude.conf:1098] | |
xplainedmini_dw = Atmel AVR XplainedMini in debugWIRE mode [/etc/avrdude.conf:1106] | |
xplainedpro = Atmel AVR XplainedPro in JTAG mode [/etc/avrdude.conf:1090] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Source: | |
* http://codesforprogram.blogspot.com/2015/08/embedded-c-code-for-arduino-to-start-as.html | |
*/ | |
#ifndef F_CPU | |
#define F_CPU 16000000UL // 16 MHz clock speed | |
#endif | |
#include <avr/io.h> | |
#include <util/delay.h> | |
int main(void) | |
{ | |
DDRB = 0xFF; //Nakes PORTC as Output | |
while(1) //infinite loop | |
{ | |
PORTB = 0xFF; //Turns ON All LEDs | |
_delay_ms(1000); //1 second delay | |
PORTB= 0x00; //Turns OFF All LEDs | |
_delay_ms(1000); //1 second delay | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment