Introduction: Programming a ATtiny2313 With Aceduino


What is an ACEDUINO? It is the Philippine Arduino clone. See pic 2 and 3.


Quote from Fall Electronics:

If you have already tried you have found out you can't use the ATTiny chips in Arduino. This is because it doesn't have the cores for the chips. A core in this context is a bunch of code and text that tells Arduino which pins are which, how fast the clock can go, how to upload the program, which functions the chip knows... basically it's an in-depth profile of the chip. 

I have tried almost every way to program an ATtiny2313 with an Arduino that i could find. For what ever reason none of them ever worked.  If you have had such a problem and want to remedy it or are just the curious type then read on.

Step 1: Not Working

Coding isn't old hat for me so all of these seamed rather complicated.
Here is some of the more common ones i had tried that i couldn't get to work: Ladyada, ToasterBotics, Hilow. I imagine these are working for a lot of people but how, i dunno.

In the picture that shows my IDE you can see the list of boards i have to choose from. There is one choice for the ATtiny2313  with no clock options.
When ever i select this option and try to compile say the blink sketch, it will always through an error. Any sketch, any time, any where.

This was one the procedure that i used here. If you can get this to work you are a better man than I.  
 

Step 2: Working

This procedure to me was clear and simple to install.

Now you can see the ATtiny2313 has 2 board choices .  As well as many others, but we are only concerned with the ATtiny2313 at this point.

ATtiny2313 @ 8MHz
ATtiny2313 @ 1MHz

Now were getting somewhere.

HERE is the magic answer for me. Its in Spanish but it translates well. When i followed there procedure all the stars aligned and spit out a programmed chip. I was very elated as i have been working on this for some 9 mo or so. Off and on. 

Step 3: Setup for Programming

This board setup was made in Fritzing by Fall Electronics.
I did not use the ( Led de estado ). They are status LED's for programming. 

There is a 10K ohm pullup resistor on the reset of the chip. Pin 1 to VCC.
There is a 10uF electrolytic capacitor on the reset of the Arduino. From the reset to ground.
These are different resets and they are not connected together in the circuit.

After you are successful with setting up the circuit then the ATtiny2313 files and confirmed they are available in the IDE you will need to set up your Arduino for programming.
In my 3rd picture you can see i am loading the ArduinoISP sketch. This makes the Arduino able to program other chips. Also note at the bottom of the IDE i have the ATmega328 board chosen to load the ArduinoISP sketch into. The complete board name is blocked in the picture so here it is:  Arduino Duemilanove w/ ATmega328. My port is on COM2.

Now that you have that completed you can continue to set up to program the ATtiny2313.
   
If you are using the 1MHz then your selection should look like pic #4.
Pic #5 shows the board that is selected at the bottom of the IDE.

From there you can load the blink sketch or what ever and burn it to the chip.

What pin is the LED connected on in the diagram?
Looks like pin 16 on the chip.

What number do we use in the IDE?
You can consult the chart and get the answer or if you prefer i will do it for you, it is 13.
Same as when you loaded the blink sketch so it doesn't need to be changed.  

Step 4: Files

Link to the board core files page or a link to the actual file download .

The file is named is: arduino-tiny-0100-0015. Its a zip file.
Download and unzip it in a folder that you can find again. You should have 2 folders " tiny " and " tools ".  
Put those 2 files directly into your hardware file. 

This is where my hardware file is:
C\Documents and Settings\WWCServer\My Documents\Arduino1.01\arduino\hardware.

When you open up the last folder the Hardware folder the 2 files you downloaded go directly in there.
Then open up the Arduino IDE you are using and check if the boards are listed.
If so load the blink sketch and compile it.  If everything was done correctly at the bottom should be the standard " Done Compiling ".
At the bottom it says the size of the file with no errors shown. See the second picture.

Step 5: Supporting Documents and Information

Any of the numbers on the chip do not correspond to the pin numbers in the Arduino IDE. That i have found.
The numbers you will need to choose in the IDE are from 0 to 16. Those numbers don not reflect the pin numbers of the chip in anyway.
If you have found the relationship between them please let me in on it!

This numbers cross reference i have made is only to get the IDE to correspond to the chip pin you want to use !

So what are they?

OK so here is what i mapped out for the numbers.
If you want to use pin #2 on the chip the IDE needs to be changed to 0

Example: The IDE is like this        int led = 13;
To use pin #2 of the chip change it to    int led = 0;

Now the remaining numbers are

Chip #          IDE #  Left side of chip
2                      0
3                      1
4                      2
5                      3
6                      4
7                      5
8                      6
9                      7

Chip #          IDE # Right side of chip
11                  8
12                  9
13                10
14                11
15                12
16                13
17                14
18                15
19                16 

Most of these pins also have other functions, see the PDF download to learn what they are.


Then of course chip pin #1 is reset
#10 is Ground
Pin # 20 is VCC

I hope this may have helped in some way.
Thanks for looking.
Comments welcomed.

Comments

author
CraigH5 (author)2016-06-14

I had a problem with my ATtiny2313 chip where I was getting a 'device signature 0x00000000' error while trying to upload a hex file or a sketch via my arduino. I thought I would post the solution to my issue here incase someone else has a similar problem.

The problem with my chip was that the 1MhZ 'fuse' was turned off when I got it from eBay (supposedly new) and the solution was to connect everything up as above and load the ISP bit then jump a wire from ~3 on the Arduino to the PA0 pin on the 2313 chip and then run the following sketch with the cap and resistor connected as described. This turned on the 1MhZ bit of the chip and allowed AVRDude and the Arduino software to talk to the chip.

I didn't write the code and it came from here. http://www.avrfreaks.net/comment/885850#comment-88...

// ArduinoISP version 04m3
// Copyright (c) 2008-2011 Randall Bohn
// If you require a license, see
// http://www.opensource.org/licenses/bsd-license.ph...
//
// This sketch turns the Arduino into a AVRISP
// using the following arduino pins:
//
// pin name: not-mega: mega(1280 and 2560)
// slave reset: 10: 53
// MOSI: 11: 51
// MISO: 12: 50
// SCK: 13: 52
//
// CLOCK_1MHZ 3: .kbv
//
// Put an LED (with resistor) on the following pins:
// 9: Heartbeat - shows the programmer is running
// 8: Error - Lights up if something goes wrong (use red if that makes sense)
// 7: Programming - In communication with the slave
//
// 23 July 2011 Randall Bohn
// -Address Arduino issue 509 :: Portability of ArduinoISP
// http://www.opensource.org/licenses/bsd-license.ph...
//
// October 2010 by Randall Bohn
// - Write to EEPROM > 256 bytes
// - Better use of LEDs:
// -- Flash LED_PMODE on each flash commit
// -- Flash LED_PMODE while writing EEPROM (both give visual feedback of writing progress)
// - Light LED_ERR whenever we hit a STK_NOSYNC. Turn it off when back in sync.
// - Use pins_arduino.h (should also work on Arduino Mega)
//
// October 2009 by David A. Mellis
// - Added support for the read signature command
//
// February 2009 by Randall Bohn
// - Added support for writing to EEPROM (what took so long?)
// Windows users should consider WinAVR's avrdude instead of the
// avrdude included with Arduino software.
//
// January 2008 by Randall Bohn
// - Thanks to Amplificar for helping me with the STK500 protocol
// - The AVRISP/STK500 (mk I) protocol is used in the arduino bootloader
// - The SPI functions herein were developed for the AVR910_ARD programmer
// - More information at http://www.opensource.org/licenses/bsd-license.ph...

#include "pins_arduino.h"
#define RESET SS

#define LED_HB 9
#define LED_ERR 8
#define LED_PMODE 7
#define PROG_FLICKER true

#define HWVER 2
#define SWMAJ 1
#define SWMIN 18

// STK Definitions
#define STK_OK 0x10
#define STK_FAILED 0x11
#define STK_UNKNOWN 0x12
#define STK_INSYNC 0x14
#define STK_NOSYNC 0x15
#define CRC_EOP 0x20 //ok it is a space...

void pulse(int pin, int times);

void setup() {
Serial.begin(19200);
pinMode(LED_PMODE, OUTPUT);
pulse(LED_PMODE, 2);
pinMode(LED_ERR, OUTPUT);
pulse(LED_ERR, 2);
pinMode(LED_HB, OUTPUT);
pulse(LED_HB, 2);
// .kbv these next statements provide a 1MHz clock signal
DDRD |= (1<<3); // make o/p
OCR2A = F_CPU/2/1000000 - 1; // CTC toggle @ 1MHz
OCR2B = OCR2A; // match B
TCCR2A = (1< 192) hbdelta = -hbdelta;
if (hbval < 32) hbdelta = -hbdelta;
hbval += hbdelta;
analogWrite(LED_HB, hbval);
delay(20);
}
void loop(void) {
// is pmode active?
if (pmode) digitalWrite(LED_PMODE, HIGH);
else digitalWrite(LED_PMODE, LOW);
// is there an error?
if (error) digitalWrite(LED_ERR, HIGH);
else digitalWrite(LED_ERR, LOW);

// light the heartbeat LED
heartbeat();
if (Serial.available()) {
avrisp();
}
}

uint8_t getch() {
while(!Serial.available());
return Serial.read();
}
void fill(int n) {
for (int x = 0; x < n; x++) {
buff[x] = getch();
}
}

#define PTIME 30
void pulse(int pin, int times) {
do {
digitalWrite(pin, HIGH);
delay(PTIME);
digitalWrite(pin, LOW);
delay(PTIME);
}
while (times--);
}

void prog_lamp(int state) {
if (PROG_FLICKER)
digitalWrite(LED_PMODE, state);
}

void spi_init() {
uint8_t x;
SPCR = 0x53;
x=SPSR;
x=SPDR;
}

void spi_wait() {
do {
}
while (!(SPSR & (1 << SPIF)));
}

uint8_t spi_send(uint8_t b) {
uint8_t reply;
SPDR=b;
spi_wait();
reply = SPDR;
return reply;
}

uint8_t spi_transaction(uint8_t a, uint8_t b, uint8_t c, uint8_t d) {
uint8_t n;
spi_send(a);
n=spi_send(b);
//if (n != a) error = -1;
n=spi_send(c);
return spi_send(d);
}

void empty_reply() {
if (CRC_EOP == getch()) {
Serial.print((char)STK_INSYNC);
Serial.print((char)STK_OK);
}
else {
error++;
Serial.print((char)STK_NOSYNC);
}
}

void breply(uint8_t b) {
if (CRC_EOP == getch()) {
Serial.print((char)STK_INSYNC);
Serial.print((char)b);
Serial.print((char)STK_OK);
}
else {
error++;
Serial.print((char)STK_NOSYNC);
}
}

void get_version(uint8_t c) {
switch(c) {
case 0x80:
breply(HWVER);
break;
case 0x81:
breply(SWMAJ);
break;
case 0x82:
breply(SWMIN);
break;
case 0x93:
breply('S'); // serial programmer
break;
default:
breply(0);
}
}

void set_parameters() {
// call this after reading paramter packet into buff[]
param.devicecode = buff[0];
param.revision = buff[1];
param.progtype = buff[2];
param.parmode = buff[3];
param.polling = buff[4];
param.selftimed = buff[5];
param.lockbytes = buff[6];
param.fusebytes = buff[7];
param.flashpoll = buff[8];
// ignore buff[9] (= buff[8])
// following are 16 bits (big endian)
param.eeprompoll = beget16(&buff[10]);
param.pagesize = beget16(&buff[12]);
param.eepromsize = beget16(&buff[14]);

// 32 bits flashsize (big endian)
param.flashsize = buff[16] * 0x01000000
+ buff[17] * 0x00010000
+ buff[18] * 0x00000100
+ buff[19];

}

void start_pmode() {
spi_init();
// following delays may not work on all targets...
pinMode(RESET, OUTPUT);
digitalWrite(RESET, HIGH);
pinMode(SCK, OUTPUT);
digitalWrite(SCK, LOW);
delay(50);
digitalWrite(RESET, LOW);
delay(50);
pinMode(MISO, INPUT);
pinMode(MOSI, OUTPUT);
spi_transaction(0xAC, 0x53, 0x00, 0x00);
pmode = 1;
}

void end_pmode() {
pinMode(MISO, INPUT);
pinMode(MOSI, INPUT);
pinMode(SCK, INPUT);
pinMode(RESET, INPUT);
pmode = 0;
}

void universal() {
int w;
uint8_t ch;

fill(4);
ch = spi_transaction(buff[0], buff[1], buff[2], buff[3]);
breply(ch);
}

void flash(uint8_t hilo, int addr, uint8_t data) {
spi_transaction(0x40+8*hilo,
addr>>8 & 0xFF,
addr & 0xFF,
data);
}
void commit(int addr) {
if (PROG_FLICKER) prog_lamp(LOW);
spi_transaction(0x4C, (addr >> 8) & 0xFF, addr & 0xFF, 0);
if (PROG_FLICKER) {
delay(PTIME);
prog_lamp(HIGH);
}
}

//#define _current_page(x) (here & 0xFFFFE0)
int current_page(int addr) {
if (param.pagesize == 32) return here & 0xFFFFFFF0;
if (param.pagesize == 64) return here & 0xFFFFFFE0;
if (param.pagesize == 128) return here & 0xFFFFFFC0;
if (param.pagesize == 256) return here & 0xFFFFFF80;
return here;
}
void write_flash(int length) {
fill(length);
if (CRC_EOP == getch()) {
Serial.print((char) STK_INSYNC);
Serial.print((char) write_flash_pages(length));
}
else {
error++;
Serial.print((char) STK_NOSYNC);
}
}

uint8_t write_flash_pages(int length) {
int x = 0;
int page = current_page(here);
while (x < length) {
if (page != current_page(here)) {
commit(page);
page = current_page(here);
}
flash(LOW, here, buff[x++]);
flash(HIGH, here, buff[x++]);
here++;
}

commit(page);

return STK_OK;
}

#define EECHUNK (32)
uint8_t write_eeprom(int length) {
// here is a word address, get the byte address
int start = here * 2;
int remaining = length;
if (length > param.eepromsize) {
error++;
return STK_FAILED;
}
while (remaining > EECHUNK) {
write_eeprom_chunk(start, EECHUNK);
start += EECHUNK;
remaining -= EECHUNK;
}
write_eeprom_chunk(start, remaining);
return STK_OK;
}
// write (length) bytes, (start) is a byte address
uint8_t write_eeprom_chunk(int start, int length) {
// this writes byte-by-byte,
// page writing may be faster (4 bytes at a time)
fill(length);
prog_lamp(LOW);
for (int x = 0; x < length; x++) {
int addr = start+x;
spi_transaction(0xC0, (addr>>8) & 0xFF, addr & 0xFF, buff[x]);
delay(45);
}
prog_lamp(HIGH);
return STK_OK;
}

void program_page() {
char result = (char) STK_FAILED;
int length = 256 * getch();
length += getch();
char memtype = getch();
// flash memory @here, (length) bytes
if (memtype == 'F') {
write_flash(length);
return;
}
if (memtype == 'E') {
result = (char)write_eeprom(length);
if (CRC_EOP == getch()) {
Serial.print((char) STK_INSYNC);
Serial.print(result);
}
else {
error++;
Serial.print((char) STK_NOSYNC);
}
return;
}
Serial.print((char)STK_FAILED);
return;
}

uint8_t flash_read(uint8_t hilo, int addr) {
return spi_transaction(0x20 + hilo * 8,
(addr >> 8) & 0xFF,
addr & 0xFF,
0);
}

char flash_read_page(int length) {
for (int x = 0; x < length; x+=2) {
uint8_t low = flash_read(LOW, here);
Serial.print((char) low);
uint8_t high = flash_read(HIGH, here);
Serial.print((char) high);
here++;
}
return STK_OK;
}

char eeprom_read_page(int length) {
// here again we have a word address
int start = here * 2;
for (int x = 0; x < length; x++) {
int addr = start + x;
uint8_t ee = spi_transaction(0xA0, (addr >> 8) & 0xFF, addr & 0xFF, 0xFF);
Serial.print((char) ee);
}
return STK_OK;
}

void read_page() {
char result = (char)STK_FAILED;
int length = 256 * getch();
length += getch();
char memtype = getch();
if (CRC_EOP != getch()) {
error++;
Serial.print((char) STK_NOSYNC);
return;
}
Serial.print((char) STK_INSYNC);
if (memtype == 'F') result = flash_read_page(length);
if (memtype == 'E') result = eeprom_read_page(length);
Serial.print(result);
return;
}

void read_signature() {
if (CRC_EOP != getch()) {
error++;
Serial.print((char) STK_NOSYNC);
return;
}
Serial.print((char) STK_INSYNC);
uint8_t high = spi_transaction(0x30, 0x00, 0x00, 0x00);
Serial.print((char) high);
uint8_t middle = spi_transaction(0x30, 0x00, 0x01, 0x00);
Serial.print((char) middle);
uint8_t low = spi_transaction(0x30, 0x00, 0x02, 0x00);
Serial.print((char) low);
Serial.print((char) STK_OK);
}
//////////////////////////////////////////
//////////////////////////////////////////
////////////////////////////////////
////////////////////////////////////
int avrisp() {
uint8_t data, low, high;
uint8_t ch = getch();
switch (ch) {
case '0': // signon
error = 0;
empty_reply();
break;
case '1':
if (getch() == CRC_EOP) {
Serial.print((char) STK_INSYNC);
Serial.print("AVR ISP");
Serial.print((char) STK_OK);
}
break;
case 'A':
get_version(getch());
break;
case 'B':
fill(20);
set_parameters();
empty_reply();
break;
case 'E': // extended parameters - ignore for now
fill(5);
empty_reply();
break;

case 'P':
start_pmode();
empty_reply();
break;
case 'U': // set address (word)
here = getch();
here += 256 * getch();
empty_reply();
break;

case 0x60: //STK_PROG_FLASH
low = getch();
high = getch();
empty_reply();
break;
case 0x61: //STK_PROG_DATA
data = getch();
empty_reply();
break;

case 0x64: //STK_PROG_PAGE
program_page();
break;

case 0x74: //STK_READ_PAGE 't'
read_page();
break;

case 'V': //0x56
universal();
break;
case 'Q': //0x51
error=0;
end_pmode();
empty_reply();
break;

case 0x75: //STK_READ_SIGN 'u'
read_signature();
break;

// expecting a command, not CRC_EOP
// this is how we can get back in sync
case CRC_EOP:
error++;
Serial.print((char) STK_NOSYNC);
break;

// anything else we will return STK_UNKNOWN
default:
error++;
if (CRC_EOP == getch())
Serial.print((char)STK_UNKNOWN);
else
Serial.print((char)STK_NOSYNC);
}
}

author
mettaurlover (author)2012-11-14

Huh, I thought these couldn't be used in an Arduino-type board because they're missing 8 pins...

author
WWC (author)mettaurlover2012-11-14

What do you mean? Used in Arduino-type boards.
Do you think i am plugging a ATtiny2313 into an Arduino board?
Because if that's what you are talking about please see step 3.

author
mettaurlover (author)WWC2012-11-14

OK, got confused for a minute. Seems like it's programmed in almost exactly the same way an ATMega328 is, just with slightly different pins.

author
WWC (author)mettaurlover2012-11-14

Yes they are programmed in the same manner. That's the beauty of Arduino.

author
maewert (author)2012-11-14

Thanks WWC! I'll have to give this a try!

author
WWC (author)maewert2012-11-14

Hi thanks for the comment.
It would be nice to see if it works for you.
Thanks

About This Instructable

8,199views

18favorites

License:

Bio: Why would i buy something ready made when i can make it myself with half the features for twice the money? DIY!
More by WWC:3D Pinted Spool ReelHard Drive Tachometer for a Desktop Computer4093 Schmidt Trigger / Fan Speed Regulation
Add instructable to: