3

3

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?

Thanks,

Riley

flag

6 Answers

3

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.

link|flag
3

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.

(* jcl *)

http://www.wiblocks.com

link|flag
3

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.

link|flag
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. – zklapow Jan 12 at 5:56
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. – davr Jan 12 at 15:44
2

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.

link|flag
2

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.

link|flag
1

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

link|flag

Your Answer

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