Program ATtiny2313 with arduino ISP (works with Arduino IDE but not in winAVR)

Hello,

Recently I stumbled on this instructable http://www.instructables.com/id/Ghetto-Programming%3A-Getting-started-with-AVR-micro/
to program AVR microcontrollers (ATtiny in my case) with a parallel port.
This worked wonderfully well.

Then I noticed that my arduino could be turned into an isp programmer. This is great because now I don't have to use that ancient computer on the attic.
I followed the steps on the arduino site and the forum to get everything ready (and since I use an arduinoUNO, they've told me to put a resistor between 5v and reset for it to work properly)
Now I can upload simple sketches written in the Arduino IDE on my ATtiny (you know, in tools->select board-> ATtiny2313 8Mhz). But, my sketches have to be really simple and since I want to use some I2C devices with my ATTiny, I can forget the Arduino IDE.

So, i want to use this instructable to learn I2C with ATtiny2313:

And instead of uploading it with winAVR on the the old computer with the parallel port, I want to use my Arduino as ISP. But that does not work.

This is what I have done:
For a test, I wanted to upload a small led-blinking program that certainly worked with the old computer with parallel port.
Since I don't use the parallel port anymore I had to change the "makefile" right?

I changed: "AVRDUDE_PROGRAMMER = dapa" -------------- into: "AVRDUDE_PROGRAMMER = avrisp" (arduino programmer is avrisp?)
"AVRDUDE_PORT = lpt1" ---------------------------------------into: "AVRDUDE_PORT = COM3" (because it is connected to COM3)

(Normally, I have attached my makefile and C program to this message)
And then I tried to get my blink sketch on my ATtiny.
But I always get:

avrdude -p attiny2313 -P COM3 -c avrisp -E reset -U flash:w:LED_Demo.hex
avrdude: WARNING: -E option not supported by this programmer type
avrdude: stk500_getsync(): not in sync: resp=0x00

avrdude done. Thank you.

make.exe: *** [program] Error 1

And the haertbeat led stops beating.

(If I do it manually wit the cmd, I get the same "not in sync" error).
And if I upload the blink example from and in the arduino IDE it works perfectly fine, so everything should be connected well.

I am not familiar with programming microcontrollers so there must be something I didn't see.

Thank you very much if you have some advice!

LED_Demo.c (473 Bytes)

Makefile (10.3 KB)

You do not need to give up the Arduino IDE (with your Arduino configured as an ISP). Just use main in your sketch instead of setup and loop...

int main( void )
{
  // put your setup here
  
  while ( true )
  {
    // put your work here
  }
}

You give up the convenience of the Arduino Core but you gain complete control over the application and the convenience of the Arduino IDE.

Two caveats: 1. Do not return from main. That path leads to chaos. 2. I believe two bytes of stack space (SRAM) are consumed entering main. If you'd like to recover those two bytes, let me know. I have a crude but effective solution.

Thank you for your reply!

Forgive my naïvity, but do you mean that I can write the c code in the Arduino IDE ?
Because if I do that, there appears to be a problem with the ATTiny core. Suddenly a bunch of stuff has not been declard or 'not being a type'.
e.g. C:...blabla... \arduino\arduino-0022\hardware\tiny\cores\tiny/TinyDebugSerial.h:651: error: 'TinyDebugSerialWriter_9600' does not name a type.

Or, if you jou just litterally meanth what you said, and leaving all the rest unchanged. I mean, I tried the "blink" example with the main and while. And it gets onto the ATtiny but the light does not blink, it just lights up. (probably something wrong with the delay function.)
But I don't think you meant the last because that would not solve much because later, I will need to upload a quite cryptic piece of code and will not be able to translate it.

Sparticles:
Forgive my naïvity, but do you mean that I can write the c code in the Arduino IDE ?

Yes, you can.

Because if I do that, there appears to be a problem with the ATTiny core. Suddenly a bunch of stuff has not been declard or 'not being a type'.

Does the sketch you are trying to compile make use of anything in the core? For example, does your sketch call pinMode?

But, my sketches have to be really simple and since I want to use some I2C devices with my ATTiny, I can forget the Arduino IDE

I believe that is what has me confused. Why do you think you have to give up the Arduino IDE?

No, not exactly, it uses this instead:

DDRD = _BV(PD4);   /* enable output on port D, pin 4 */

and similar things that are defined in a header file included in some winAVR folder. (I tried copying those header files into the same folder of the project but it doesn't have an effect.)

Oh because I started adding a little bit to the blink example (like trying to add a library (the Morse one) and I got over the 2048 byte maximum really fast. And my program was not nearly as big as the one with the 2IC which I wanted to upload later. (but alright, it was just testing and probably very dirty programming)
And I can only open processing files or files with the extension .pde (and I thought one could only use the arduino/processing code.)

and similar things that are defined in a header file

<avr/io.h> ?

And I can only open processing files or files with the extension .pde (and I thought one could only use the arduino/processing code.)

Each sketch has to have a dot-pde file but you can also have any number of dot-h, dot-c, and dot-cpp files. The only thing special about the dot-pde is that the Arduino IDE performs some pre-processing on it. Other than that it is essentially a dot-cpp file.

<avr/io.h> ?

Indirectly yes. It includes specifically <avr/interrupt.h> but that one includes <avr/io.h>.

Each sketch has to have a dot-pde file but you can also have any number of dot-h, dot-c, and dot-cpp files.

Ah, well I can't 'open' .h .c or .cpp files but I do can use the function "add file" and 'manage' those files in extra tabs. But compiling doesn't work.
(Importing self written libraries (c++) works fine btw.)

Is it maybe impossible to use the Arduino without the IDE just like an ordinary USP ISP programmer? You know, for programming via WinAVR with the 'makefile'.
(Although if it is possible to use the Arduino for that, it will find it a million times better, so don't get me wrong.)

But compiling doesn't work

Should. Post details.

Is it maybe impossible to use the Arduino without the IDE just like an ordinary USP ISP programmer?

I just noticed from your original post...

avrdude -p attiny2313 -P COM3 -c avrisp -E reset -U flash:w:LED_Demo.hex

The Arduino ISP sketch implements a subset of the STK500 protocol.

avrdude -Cavrdude.conf -v -v -v -v -pattiny85 -cstk500v1 -P\.\COM9 -b57600 -Uflash:w:build2548543659733176588.tmp\OneWire_004_SearchOnly.cpp.hex:i

Should.  Post details.

It does now! I don't know what happened exactly, I tried some things and got the usual ton of errors. Then I tried all sorts of things. The last thing I did in the arduino IDE (before switching to avrdude) was the 'burn bootloader -> w\ Arduino ISP' . You know, just to try if the programming lights were blinking. (But I do not know if it is because of that it works now)
Then I switched to avrdude to try the thing you suggested with "-cstk500v1".
And when I came back to the arduino IDE and tried the LED_Demo again and there were no errors anymore (after a few tries). I find it strange. With the parallel port, there was no need of a bootloader and uploading 'examples' in the Arduino language worked too.

Well, I am very glad this works now! Thank you very much for pointing out that the IDE could be used for this.

And about the avrdude:
I've tried with "-cstk500v1" but no succes. ( I had a different error sometimes though "..._timeout()" )
but I found this old topic: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1277933355 .

Here someone named Osgeld suggested:

avrdude -c avrisp -p insert_part_name -P insert_com_port -b 19200 -U flash:w:filename.hex

(and it is suggested many times more in that thread)
But then again, I see that it didn't help much.

wlewis said:

5. Also, if youre able to upload arduino sketches successfully you should be able to use avrdude with equal success.

Which isn't the case.

But at least I can continue with my Arduino IDE now.
So thank you very much for your patience.

Thank you for the follow-up. I'm glad you hate it working.

I'm glad you hate it working.

Is that a Tiny secret joke between users? :wink:

XD Yikes! Nope. Fingers typing response while brain doing day-job crap.

As if I wasn't distracted enough today, the goody box for Digi-Key just arrived and that pesky dog of mine is tearing open the box!