Skip to content

Instantly share code, notes, and snippets.

@dwaq
Last active October 23, 2023 18:43
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save dwaq/8239080 to your computer and use it in GitHub Desktop.
Save dwaq/8239080 to your computer and use it in GitHub Desktop.
How to program ATTINY13A with Arduino as ISP http://tinkeringetc.blogspot.com/

How to program ATtiny13A with Arduino as ISP


Install WinAVR

http://winavr.sourceforge.net/

Set fuse bits

Determine what bits using http://www.engbedded.com/fusecalc

  • DO CHECK "Serial program downloading"

  • DO NOT CHECK "Reset Disabled"

      -U lfuse:w:0x7a:m -U hfuse:w:0xff:m
    

for ATtiny13

Blink.cpp

  • LED on pin 2 of ATtiny

      #include <avr/io.h>
      #include <util/delay.h>
    
      int main(void)
      {
        DDRB = 1<<3; // port B3, ATtiny13a pin 2
        PORTB = 0x0;
    
        while (1)
        {
          PORTB = 1<<3; // port B3, ATtiny13a pin 2
          _delay_ms(500);
          PORTB = 0X0;
          _delay_ms(250);
        }
      }
    

Compiling Blink.cpp

1) Using avr-gcc

avr-gcc -g -DF_CPU=9600000 -Wall -Os -mmcu=attiny13a -c -o tmp.o blink.cpp
avr-gcc -g -DF_CPU=9600000 -Wall -Os -mmcu=attiny13a -o tmp.elf tmp.o
avr-size tmp.elf
avr-objcopy -j .text -j .data -O ihex tmp.elf tmp.hex

or put in a batch file (build.bat) with pause at the end to read output when double-clicked

2) Using a makefile

Just type make in cmd prompt of directory where makefile is located

Program Arduino as ISP

  • Use ISP sketch in Arduino program (Examples -> Arduino ISP)
  • Change baud rate to 9600

Put an LED and series resistor on the following pins to see the programming status:

9	Heartbeat		shows the programmer is running
8	Error			Lights up if something goes wrong
7	Programming		In communication with the slave

Connect Arduino and ATTiny13a as follows:

Signal name		ArduinoISP	ATtiny13A
SCK				13			7
MISO			12			6
MOSI			11			5
SS/reset		10			1
GND				GND         4
VCC				5V			8

Description of pins:

SCK		serial clock (output from master)
MISO	master input, slave output (output from slave)
MOSI	master output, slave input (output from master)
SS		slave select (active low, output from master)

Program Fuse bits

avrdude -p attiny13 -P com4 -c stk500v1  -b 9600 -q -U lfuse:w:0x7a:m -U hfuse:w:0xff:m

Uploading program

avrdude -p attiny13 -c stk500v1 -P com4 -b 9600 -q -U flash:w:tmp.hex

Notes from http://letsmakerobots.com/node/31379

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