In this tutorial I will show you how to program an ATtiny2313 microcontroller chip using Arduino.
What is ATtiny2313 ATtiny4313
The ATtiny2313 and ATtiny4313 are 20 pin processor chips. It has 17 I/O pins, but it do not have an ADC. It can be configured to run at 1 MHz and 8 MHz without an External Crystal Oscillator. I previously shown you how to program the ATtiny85 using Arduino, which is an 8 pin chip suitable for much smaller projects.
Connection with the Arduino
Connect your Arduino to the Attiny2313 following these pins.
Arduino Attiny2313 13 19 PB7/SCK 12 18 PB6/MISO 11 17 PB5/MOSI 10 1 PA2/Reset 5v 20 VCC GND 10 GND
Arduino-Tiny Libraries and Arduino IDE
- Download the Arduino-Tiny library.
- Follow these instructions to install the library. (make sure the Arduino IDE is NOT running yet!)
- Upload the ArduinoISP to the Arduino
- Connect a 10 µF capacitor from reset to ground on the Arduino (If you are using Arduino Duemilanove use an 120 ohm resistor from reset to Vcc)
- Open the blink example sketch, change the LED pin number from 13 to 15 (which is pin 18 on the chip)
- Select Attiny2313 board from Tools->Board-> Attiny2313@1MHZ. You will notice that you have a lot of options to choose. This is because that ‘tiny’ folder that we put in the ‘hardware’ folder gave the Arduino program more board options.
- Select ArduinoISP: Tools->Programmer->Arduino as ISP
- Upload your sketch by selecting File->Upload using programmer, if you are getting any error, check out this post to troubleshoot the problem.
- Connect a LED with resistor to pin PB6 on the ATtiny2313 or 4313 (pin number 18 on the chip)
- Now you should have a blinking LED on your Attiny2313
Check this diagram to match the pin number we use in programming and the physical pin location.
Running at different speed
Note the chip will run at 1 MHz in the above example, as specified when selecting the ATtiny board in the IDE. If you want to run it at 8 MHz you need to use select a different board option and also the burn bootloader option. It does not really burn a bootloader on your ATtiny chip, it will only set the fuses to another clock-speed. Also it’s recommended to connect an 0.1 uF capacitor between VCC and GND, and an 10 Kohm resistor between RESET and VCC when running at this speed.
Select board -> Attiny2313@8MHZ Select ->Tools->Programmer->Arduino as ISP Select ->Tools->Burn Bootloader
Debugging ATtiny and display information on the Arduino IDE
Easiest way to debug the Arduino is using Serial.print() function, and fortunately you can also do that on the Attiny2313 too.
The difference between ATtiny2313 and ATtiny4313
I have not got a ATtiny4313 yet so I can’t test this Arduino programming method on it. But they seems to be very similar as they appear on the same datasheet. The datasheet says “The ATtiny2313A and ATtiny4313 differ only in memory sizes.” So I suppose all you need to do is to select the different board before upload the sketch in the IDE. I will update this section once I am sure of this, or let me know to confirm it if you have done it.
Programming ATtiny chips with Arduino using Shields
Connecting the cables every time you want to program a ATtiny chip is quite time-consuming and messy. This instructable is quite handy if you are a frequency ATtiny chip programmer.
8 comments
Hi Oscar i have a problem, you did great job, but theres a problem with bytes and pixels, i tried some code on arduino uno(works perfectly), but when i try to upload it to 4313 it dosen’t work. i dunno why
arduino_function_gen.ino: In function ‘void setup()’:
arduino_function_gen:60: error: ‘DDRC’ was not declared in this scope
arduino_function_gen:75: error: ‘TIMSK1’ was not declared in this scope
arduino_function_gen:83: error: ‘A5’ was not declared in this scope
arduino_function_gen:87: error: ‘A4’ was not declared in this scope
arduino_function_gen.ino: In function ‘void checkFreq()’:
arduino_function_gen:98: error: ‘A5’ was not declared in this scope
arduino_function_gen.ino: In function ‘void checkPW()’:
arduino_function_gen:117: error: ‘A4’ was not declared in this scope
arduino_function_gen.ino: In function ‘void checkShape()’:
arduino_function_gen:132: error: ‘A0’ was not declared in this scope
arduino_function_gen:135: error: ‘A1’ was not declared in this scope
arduino_function_gen:138: error: ‘A2’ was not declared in this scope
arduino_function_gen:141: error: ‘A3’ was not declared in this scope
htlinux.com/product/attiny-isp-shield
Here is the ATTiny ISP Shield makes the job very much easier.
Hello,
on the page https://code.google.com/p/arduino-tiny/
one can choose between
Download the latest version for Arduino 1.0
and
Download the latest version for Arduino 1.5
Which version do I need?
I have Arduino Uno R3 with Arduino IDE 1.0.6
Thanks for help,
Sigi
try the one I provided in the post (URL in the post)
avrdude: stk500_getsync(): not in sync: resp=0x00
What is the problem?
Hi Oscar,
I’m having no luck with the 4313.
I’m able to write to other avr’s no problem, but i get an error message that basically says the attiny4313 is not in the boards list even though it is. I updated the definitions from google and followed your procedure exactly as discribed to update using Winavr. I still get the same message that states: unknown MCU ‘attiny4313 specified.
Then lists known MCU names but doesn’t include 4313. I’m stumped my boards difinition list shows both 4313 variations 1 and 8 mhz. I’m using arduino 1.0.5 and a UNO. Like I say i program other device with no problems including the 2313.
Please help!!!
Best regards,
Ron Wright
Hi Ron,
4313 are not supported by the version of WinAVR included with Arduino.
See what Jonathan did… jagough.com/
/Anders
download WinAVR file
put all the contents from WinAVR in:
C:Arduinohardwaretoolsavr
move avrdude.conf from C:Arduinohardwaretoolsavrbin to C:Arduinohardwaretoolsavretc
you will have to create the etc directory
Edit the avrdude.conf file and put this after the ATtiny2313 and you will be able to program the ATtiny4313! What a pain in the butt. I wanted to save someone the trouble I went through to figure this out. Good Luck
#————————————————————
# ATtiny4313
#————————————————————
part
id = “t4313”;
desc = “ATtiny4313”;
has_debugwire = yes;
flash_instr = 0xB2, 0x0F, 0x1F;
eeprom_instr = 0xBB, 0xFE, 0xBB, 0xEE, 0xBB, 0xCC, 0xB2, 0x0D,
0xBA, 0x0F, 0xB2, 0x0F, 0xBA, 0x0D, 0xBB, 0xBC,
0x99, 0xE1, 0xBB, 0xAC;
stk500_devcode = 0x23;
## Use the ATtiny26 devcode:
avr910_devcode = 0x5e;
signature = 0x1e 0x92 0x0d;
pagel = 0xD4;
bs2 = 0xD6;
reset = io;
chip_erase_delay = 9000;
pgm_enable = “1 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1”,
“x x x x x x x x x x x x x x x x”;
chip_erase = “1 0 1 0 1 1 0 0 1 0 0 x x x x x”,
“x x x x x x x x x x x x x x x x”;
timeout = 200;
stabdelay = 100;
cmdexedelay = 25;
synchloops = 32;
bytedelay = 0;
pollindex = 3;
pollvalue = 0x53;
predelay = 1;
postdelay = 1;
pollmethod = 1;
pp_controlstack =
0x0E, 0x1E, 0x0E, 0x1E, 0x2E, 0x3E, 0x2E, 0x3E,
0x4E, 0x5E, 0x4E, 0x5E, 0x6E, 0x7E, 0x6E, 0x7E,
0x26, 0x36, 0x66, 0x76, 0x2A, 0x3A, 0x6A, 0x7A,
0x2E, 0xFD, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00;
hventerstabdelay = 100;
progmodedelay = 0;
latchcycles = 5;
togglevtg = 1;
poweroffdelay = 15;
resetdelayms = 1;
resetdelayus = 0;
hvleavestabdelay = 15;
chiperasepulsewidth = 0;
chiperasepolltimeout = 10;
programfusepulsewidth = 0;
programfusepolltimeout = 5;
programlockpulsewidth = 0;
programlockpolltimeout = 5;
memory “eeprom”
size = 256;
paged = no;
page_size = 4;
min_write_delay = 4000;
max_write_delay = 4500;
readback_p1 = 0xff;
readback_p2 = 0xff;
read = “1 0 1 0 0 0 0 0 0 0 0 x x x x x”,
“a7 a6 a5 a4 a3 a2 a1 a0 o o o o o o o o”;
write = “1 1 0 0 0 0 0 0 0 0 0 x x x x x”,
“a7 a6 a5 a4 a3 a2 a1 a0 i i i i i i i i”;
loadpage_lo = ” 1 1 0 0 0 0 0 1″,
” 0 0 0 0 0 0 0 0″,
” 0 0 0 0 0 0 a1 a0″,
” i i i i i i i i”;
writepage = ” 1 1 0 0 0 0 1 0″,
” 0 0 x x x x x x”,
” a7 a6 a5 a4 a3 a2 0 0″,
” x x x x x x x x”;
mode = 0x41;
delay = 6;
blocksize = 4;
readsize = 256;
;
memory “flash”
paged = yes;
size = 4096;
page_size = 64;
num_pages = 64;
min_write_delay = 4500;
max_write_delay = 4500;
readback_p1 = 0xff;
readback_p2 = 0xff;
read_lo = ” 0 0 1 0 0 0 0 0″,
” 0 0 0 0 0 a10 a9 a8″,
” a7 a6 a5 a4 a3 a2 a1 a0″,
” o o o o o o o o”;
read_hi = ” 0 0 1 0 1 0 0 0″,
” 0 0 0 0 0 a10 a9 a8″,
” a7 a6 a5 a4 a3 a2 a1 a0″,
” o o o o o o o o”;
loadpage_lo = ” 0 1 0 0 0 0 0 0″,
” 0 0 0 x x x x x”,
” x x x a4 a3 a2 a1 a0″,
” i i i i i i i i”;
loadpage_hi = ” 0 1 0 0 1 0 0 0″,
” 0 0 0 x x x x x”,
” x x x a4 a3 a2 a1 a0″,
” i i i i i i i i”;
writepage = ” 0 1 0 0 1 1 0 0″,
” 0 0 0 0 0 a10 a9 a8″,
” a7 a6 a5 x x x x x”,
” x x x x x x x x”;
mode = 0x41;
delay = 6;
blocksize = 32;
readsize = 256;
;
# ATtiny4313 has Signature Bytes: 0x1E 0x92 0x0D.
memory “signature”
size = 3;
read = “0 0 1 1 0 0 0 0 0 0 0 x x x x x”,
“x x x x x x a1 a0 o o o o o o o o”;
;
memory “lock”
size = 1;
write = “1 0 1 0 1 1 0 0 1 1 1 x x x x x”,
“x x x x x x x x 1 1 i i i i i i”;
read = “0 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0”,
“x x x x x x x x x x o o o o o o”;
min_write_delay = 9000;
max_write_delay = 9000;
;
memory “lfuse”
size = 1;
write = “1 0 1 0 1 1 0 0 1 0 1 0 0 0 0 0”,
“x x x x x x x x i i i i i i i i”;
read = “0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0”,
“x x x x x x x x o o o o o o o o”;
min_write_delay = 9000;
max_write_delay = 9000;
;
memory “hfuse”
size = 1;
write = “1 0 1 0 1 1 0 0 1 0 1 0 1 0 0 0”,
“x x x x x x x x i i i i i i i i”;
read = “0 1 0 1 1 0 0 0 0 0 0 0 1 0 0 0”,
“x x x x x x x x o o o o o o o o”;
min_write_delay = 9000;
max_write_delay = 9000;
;
memory “efuse”
size = 1;
write = “1 0 1 0 1 1 0 0 1 0 1 0 0 1 0 0”,
“x x x x x x x x x x x x x x x i”;
read = “0 1 0 1 0 0 0 0 0 0 0 0 1 0 0 0”,
“x x x x x x x x o o o o o o o o”;
min_write_delay = 9000;
max_write_delay = 9000;
;
memory “calibration”
size = 2;
read = “0 0 1 1 1 0 0 0 0 0 0 x x x x x”,
“0 0 0 0 0 0 0 a0 o o o o o o o o”;
;
;