Arduino as ISP

I prefer to develop in pure C instead of using the Arduino framework, for both learning and code size purposes. I use the Arduino board solely as an AVR programmer, using my script qAVR to flash the microcontroller.

## material
– breadboard
– jumper wires
– 10µF capacitor
– 220 ohms resistor
– LED
– Arduino
– Target microcontroller (in our example, attiny2313)

## install dev env
pacman -S avr-gcc avr-libc avrdude
wget https://raw.githubusercontent.com/xdth/qavr/master/qavr (place it in your .bin folder)

## Set Arduino as ISP
– in IDE, check board type, serial port
– load and burn ArduinoISP
– type dmesg -wH and get the device name (ttyACM0 in our example)

## Check datasheets and make the connections

+-------+------------+--------+
|       | attiny2313 |  ISP   |
+-------+------------+--------+
| VCC   | PIN 20     | 5V     |
| GND   | PIN 10     | GND    |
| RESET | PIN 1      | PIN 10 |
| MISO  | PIN 17     | PIN 11 |
| MOSI  | PIN 18     | PIN 12 |
| SCK   | PIN 19     | PIN 13 |
+-------+------------+--------+

* Disable auto-reset of the arduino by placing an 10µF capacitor from reset to ground

## To use the internal clock
– makefile 8000000
– code.c F_CPU 1000000 (fuses divide the clock by 8 internally)

## hello world
– Connect the LED to the target chip (PD6/pin11+led-220ohms-gnd)

/* main.c */

#define F_CPU 1000000  // CPU frequency
#include <avr/io.h>
#include <util/delay.h>

int main(void) {
  DDRD |= (1 << PD6);  // set PD6 as output

  for(;;) {
    PORTD ^= (1 << PD6);  // to toggle PD6
    _delay_ms(1000);  // 1s delay
  }

  return 0;  // success
}

## Burn the hello world
sudo qavr -d /dev/ttyACM0 -m attiny2313 -f main.c

Leave a Reply

Your email address will not be published.

Loading Facebook Comments ...
Loading Disqus Comments ...