Skip to content

Instantly share code, notes, and snippets.

@jbobrow
Last active December 30, 2019 06:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbobrow/515b3c1dc0ede2d49030 to your computer and use it in GitHub Desktop.
Save jbobrow/515b3c1dc0ede2d49030 to your computer and use it in GitHub Desktop.
A quick and dirty explanation of the process for getting your C program onto an ATtiny using the FabISP. Intended for HTMAA 2015

##Embedded Programming Notes ######by Jonathan Bobrow

Here is a quick and dirty explanation of the process for getting your C program onto an ATtiny using the FabISP.

In short, this is using the included make file that Neil provides. The following three commands will allow you to (1)compile your C application, (2)set fuses on your ATtiny, (3)upload your embedded program to the ATtiny.

  1. make -f <name_of_application>.make
  2. make -f <name_of_application>.make program-usbtiny-fuses
  3. make -f <name_of_application>.make program-usbtiny

note: you only need to do step 2 on the first time (setting the fuses can be a 1 time thing)

note deux: check to make sure your ISP is connected properly and that your board has power (i.e. not just the ISP, also connect an FTDI or other power source), you will get errors otherwise.

tercera nota: if you want to check that your FabISP is showing up connected to USB, on a mac, you can enter this command: system_profiler SPUSBDataType into terminal or this command ioreg -p IOUSB -w0 | sed 's/[^o]*o //; s/@.*$//' | grep -v '^Root.*' for a succint list of just the names

##Step 1 Making our Hex file (translating from C to machine language which the ATtiny is happy to obey)

$ make -f blink_button.c.make
avr-gcc -mmcu=attiny44 -Wall -Os -DF_CPU=20000000 -I./ -o blink_button.out blink_button.c
In file included from blink_button.c:2:0:
/usr/local/CrossPack-AVR-20131216/avr/include/avr/delay.h:36:2: warning: #warning "This file has been moved to <util/delay.h>." [-Wcpp]
 #warning "This file has been moved to <util/delay.h>."
  ^
avr-objcopy -O ihex blink_button.out blink_button.c.hex;\
	avr-size --mcu=attiny44 --format=avr blink_button.out
AVR Memory Usage
----------------
Device: attiny44

Program:     108 bytes (2.6% Full)
(.text + .data + .bootloader)

Data:          0 bytes (0.0% Full)
(.data + .bss + .noinit)

##Step 2 Now we have to set our Fuses on the ATtiny, so we do this step once (this tells the chip what speed to operate at among other things if you so please)

You will only need to set your Fuses once, so skip this step when testing out modifications to your code to save time.

$ make -f blink_button.c.make program-usbtiny-fuses
avr-objcopy -O ihex blink_button.out blink_button.c.hex;\
	avr-size --mcu=attiny44 --format=avr blink_button.out
AVR Memory Usage
----------------
Device: attiny44

Program:      96 bytes (2.3% Full)
(.text + .data + .bootloader)

Data:          0 bytes (0.0% Full)
(.data + .bss + .noinit)


avrdude -p t44 -P usb -c usbtiny -U lfuse:w:0x7E:m

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e9207
avrdude: reading input file "0x7E"
avrdude: writing lfuse (1 bytes):

Writing | ################################################## | 100% 0.00s

avrdude: 1 bytes of lfuse written
avrdude: verifying lfuse memory against 0x7E:
avrdude: load data lfuse data from input file 0x7E:
avrdude: input file 0x7E contains 1 bytes
avrdude: reading on-chip lfuse data:

Reading | ################################################## | 100% 0.00s

avrdude: verifying ...
avrdude: 1 bytes of lfuse verified

avrdude: safemode: Fuses OK (H:FF, E:DF, L:7E)

avrdude done.  Thank you.

##Step 3 Now we want to actually write the machine language onto the ATtiny, so this command will do just that. Note that it first erases the existing application, then proceeds to write in its place.

$ make -f blink_button.c.make program-usbtiny
avr-objcopy -O ihex blink_button.out blink_button.c.hex;\
	avr-size --mcu=attiny44 --format=avr blink_button.out
AVR Memory Usage
----------------
Device: attiny44

Program:     108 bytes (2.6% Full)
(.text + .data + .bootloader)

Data:          0 bytes (0.0% Full)
(.data + .bss + .noinit)


avrdude -p t44 -P usb -c usbtiny -U flash:w:blink_button.c.hex

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e9207
avrdude: NOTE: "flash" memory has been specified, an erase cycle will be performed
         To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: reading input file "blink_button.c.hex"
avrdude: input file blink_button.c.hex auto detected as Intel Hex
avrdude: writing flash (108 bytes):

Writing | ################################################## | 100% 0.13s

avrdude: 108 bytes of flash written
avrdude: verifying flash memory against blink_button.c.hex:
avrdude: load data flash data from input file blink_button.c.hex:
avrdude: input file blink_button.c.hex auto detected as Intel Hex
avrdude: input file blink_button.c.hex contains 108 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 0.15s

avrdude: verifying ...
avrdude: 108 bytes of flash verified

avrdude: safemode: Fuses OK (H:FF, E:DF, L:7E)

avrdude done.  Thank you.

For more help, check sources such as Adafruit or google and you will surely be led to many HTMAA class pages :) Also, don't forget to email your class list, the shared knowledge and search power of your class is quite powerful!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment