11
\$\begingroup\$

I have been coding and using Arduinos for quite some time now. However I am ready to move up to using straight AVR chips without the arduino bootloader. My question is what are resources to do this?

I want to use linux / mac so winavr is out of the picture as is avrstudio. If there is no such thing as what I am after I will settle for a windows virtual machine. But until I know for sure. What I want is some type of IDE that uses avr-gcc.

As a bonus to this question does anyone have any good resources on learning C for avr? Specifically how to configure Makefiles etc for the various different chips?

\$\endgroup\$

10 Answers 10

7
\$\begingroup\$

I agree with zklapow but check the projects section on AVR Freaks too. That's how I learnt back in the day before arduinos. Also, you will almost certainly have to read the datasheet for your chip to get anything useful done. There are no nice functions that, for example, read an analog pin in because there are so many parameters that the arduino environment hides from you. Let me give you an example:

 int ledPin =  13;    // LED connected to digital pin 13
 // The setup() method runs once, when the sketch starts
 void setup()   {                
   // initialize the digital pin as an output:
   pinMode(ledPin, OUTPUT);     
 }
 // the loop() method runs over and over again,
 // as long as the Arduino has power
 void loop()                     
 {
   digitalWrite(ledPin, HIGH);   // set the LED on
   delay(1000);                  // wait for a second
   digitalWrite(ledPin, LOW);    // set the LED off
   delay(1000);                  // wait for a second
 }

is roughly similar to the following C (not tested):

int main(void) {
    // I just randomly picked pin 6 on PORTB, this may not be the same on an arduino
    DDRB = (1<<6); // set pin to output in data direction register
    int i; // have to do this outside the for loop because of C standard

    while(1) {
        PORTB |= (1<<6); // send pin 6 high and leave other pins in their current state
        for (i=0; i<10000; i++); // delay

        PORTB &= ~(1<<6); // send pin 6 low
        for (i=0; i<10000; i++); // delay
    }
}

Sure, there are delay functions in some libraries and there may be output functions in other ones, but get used to writing code like this. The only way you can possibly know what all this PORTB and DDRB stuff means is to read the datasheet. I'm sorry to drone on about this but not enough people realize that the datasheet is a goldmine for information.

\$\endgroup\$
2
  • \$\begingroup\$ I would make one correction to your code, when you set DDRB you should use DDRB |=(1<<6) so as not to affect an other bits. \$\endgroup\$
    – zklapow
    Jan 12, 2010 at 5:56
  • \$\begingroup\$ Also there is a delay_ms() function available. But in general, in more complex programs, you usually do not want to be hard coding delays into your app. \$\endgroup\$
    – davr
    Jan 12, 2010 at 15:44
7
\$\begingroup\$

You should also check out Eclipse for C/C++ and the AVR-Eclipse plugin. Works flawlessly for me, especially with crosspack. I use it for about a year now and I really like it.

\$\endgroup\$
2
  • \$\begingroup\$ Get the avr-eclipse plugin, it integrates nicely with avrdude and avr-gcc so you end up with a nice IDE on top of a good, free compiler. \$\endgroup\$
    – dren.dk
    Mar 25, 2011 at 8:32
  • \$\begingroup\$ the Eclipse microcontroller setup will be a good gateway to using ARM microcontrollers as well. Much better alternative than getting an AVR only IDE. \$\endgroup\$
    – lyncas
    Mar 21, 2012 at 19:37
4
\$\begingroup\$

I use ObDev's CrossPack as well. It's a great bundling of all the tools needed to write AVR-GCC C code. They're the same tools present in a standard Arduino installation, so sometimes I've used the guts of the Arduino build system to write plain AVR-GCC code.

Normally when I write C code, the "IDE" I use is a text editor, command-line commands, and Makefiles. I'm just more efficient that way. I have one window open that's the text editor (emacs), another window that's compilation, and a third or fourth that's doing serial monitor or similar. But all that can be done in a single command-line window, in which case the commands look something like:

% emacs foo.c [edit file]
% make        [compile code]
% make flash  [upload to chip]
% screen /dev/tty.usbserial 9600  [talk to chip]
... and then repeat as needed...

Also, you may want to check out SmileyMicros.com. He wrote a really nice book on intro AVR GCC programming based on the AVR Butterfly board, before the Arduino, and has since been updating his examples to incorporate Arduino. It's a nice comparison to see how AVR C programming is done on a more complex chip than the one in Arduino.

\$\endgroup\$
3
\$\begingroup\$

If you install crosspack you can use Apple's Xcode for mac, which is a great IDE. If you want learn c for AVR check out the tutorials forum at AVR Freaks. Also as for linux check out this question.

\$\endgroup\$
3
\$\begingroup\$

Since you have been using the Arduino everything you need is already installed. I compile Arduino sketches from the command line using a Makefile. I also compile code without the Arduino bootloader.

The Makefile I use to compile the Arduino bootloader for my boards is at http://wiblocks.luciani.org/docs/app-notes/bootloader.html You could modify it to compile your program rather than the ATmegaBOOT_xx8.c file.

My Makefile is modified from the file I found at this site -- http://mjo.tc/atelier/2009/02/arduino-cli.html

While answering this same question (just yesterday;) on twitter I came across a makefile at dorbotpdx. See http://dorkbotpdx.org/blog/ax/arduino_0017_makefile

There is also a well documented shell script at http://arkku.com/misc/arduino_make.sh

I would probably use a Makefile rather than a shell script. The fellow that did this script has done an excellent job of commenting the flow. It is work a look just to understand the flow.

\$\endgroup\$
2
  • \$\begingroup\$ I was not able to make arduino_make.sh work w/ OSX 10.6 because 'awk -v' doesn't work as expected on OSX and he uses it everywhere. \$\endgroup\$
    – terrace
    Mar 24, 2011 at 21:28
  • \$\begingroup\$ His question was not about Arduino, but about using avr-gcc and avrdude on Linux \$\endgroup\$
    – dren.dk
    Mar 25, 2011 at 8:31
2
\$\begingroup\$

I found CodeLite (www.codelite.org) IDE nice and full featured; still, to program AVR microchips you need to create your own Makefile.

You could try BeRTOS Wizard, which will create a BeRTOS project and related Makefiles, which you can then use with CodeLite. To flash your target, just use "make flash" and you're done. We work on Linux on a daily basis, if you have further question please post them on the mailing list. Disclaimer: I'm a BeRTOS developer.

Best regards, Luca

\$\endgroup\$
1
  • \$\begingroup\$ Disclaimer aside, CodeLite is a great tool. You don't have to use 'make flash' if you configure CodeLite to work with your build system. Code::Blocks has similar potential. \$\endgroup\$ Mar 24, 2011 at 21:21
2
\$\begingroup\$

If you have got Macports installed you can simply run:

$ sudo port install avr-binutils avr-gcc avr-libc avrdude 

and you should be ready to go.

\$\endgroup\$
2
\$\begingroup\$

If you ask your package system to install avr-libc, that should give you all you need. I use emacs as my IDE, cos, well, see username.

If you want a template makefile, have a look at one of my projects on github, eg https://github.com/unixbigot/pir-lite

In that repo avr-tmpl.mk is an off-the-shelf makefile library (not written by me). You include it from your main makefile and you only have to define which chip you have, the clock speed, and your files. I have one copy of it and include it from all my project makefiles.

"make program" will call avrdude to download the code. The makefile also prints out code size at end, so you know how much room you have left.

\$\endgroup\$
0
\$\begingroup\$

I programmed my 'old' Duemanilove' as ISP with the help of this article: http://arduino.cc/en/Tutorial/ArduinoISP It works equally well wit ATtiny's: http://hlt.media.mit.edu/?p=1229

Mind you, when using Arduino IDE 0022, you need to upgrade the ArduinoISP sketch to a more recent version, due to spam prevention I moved that link to the comments below.

I did the programming in a text editor (vi) and compiled using avr-gcc as described in the mit.edu article I linked.

\$\endgroup\$
1
0
\$\begingroup\$

Hey dude you can still use avrstudio in ubuntu. Thinking how can you do that .....

Answer is just install wine application and run those windows softwares with wine.

Avr studio, proteus ... even games of windows can be run in ubuntu with wine.

You dont have to even mess with the makefiles blah blah.(just install with wine and get started).

There are many sites to get started with avr MCU's like extremeelectronics , AVR tutorials etc. Just give a google search.

I will tell in detail how to install avrstudio 4 in wine since avrstudio 5 and 6 doesn't work with it but you can use virtual box in linux to run even avr stud 5 and 6 with windows on virtual box.

  1. Open Ubuntu software center and type wine in the search and then install it.

  2. Then get the setup for avrstudio4 and also you need to install win avr

    try these links for

a. avr studio 4 http://mycomsats.com/blogs/download-atmel-avr-studio-4-free/

b. win avr http://sourceforge.net/projects/winavr/files/WinAVR/20100110/WinAVR-20100110-install.exe/download?use_mirror=kaz&r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fwinavr%2Ffiles%2F&use_mirror=kaz

3.Open the folder where the setup for AS(avr studio 4) is and then right click and then open it with "windows wine program loader" or "a wine application".

4.Then you need to click on the next buttons as you would do it in windows.

5.Then again install win avr similarly with wine(go into the win avr setup ....).

6.Download the classic menu indicator from ubuntu software center. You will get to know about it in just five minutes.

7.From the classic menu -> wine -> Programs -> avr tools

the sixth step is an extra step so that you dont have to mess with where the avrstudio4 executable option is in the wine folder.

\$\endgroup\$
2
  • \$\begingroup\$ This answer would be more useful if it contained details / links as to how to run it under Wine. The latest Atmel Studio is based on Microsoft Visual Studio which I believe doesn't work well under Wine, but I could be wrong. \$\endgroup\$
    – PeterJ
    Jul 20, 2014 at 7:18
  • \$\begingroup\$ I have edited the answer @PeterJ \$\endgroup\$
    – Jasser
    Jul 20, 2014 at 9:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.