Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.
0

AVR commands
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

AVR commands

by mschiff on Thu Feb 18, 2010 5:22 pm

So I am shifting from the Arduino system to a proto-board and AVR chip that I am programming with AVR dude and the usbTinyIsp.

I am hoping that someone can point me toward a reference for chips functions.

I know that the arduino functions like 'digitalWrite()' etc are just sets of multiple individual commands, so I guess the best thing I could find would be the definitions for all of these functions. Would things like that be located in the IDE? on my computer?
-Michael-
mschiff
 
Posts: 26
Joined: Tue Feb 02, 2010 3:35 pm

Re: AVR commands

by westfw on Thu Feb 18, 2010 6:29 pm

AVR Instruction set: http://www.atmel.com/dyn/resources/prod ... oc0856.pdf This is applicable to all of the AVR chips, but it doesn't talk much about the actual AVR architecture (registers, etc.)
ATmega328P summary data sheet: http://www.atmel.com/dyn/resources/prod ... /8271S.pdf
ATmega328P full data sheet: http://www.atmel.com/dyn/resources/prod ... s/8271.pdf
You might want to look for tutorials at http://avrfreaks.net and http://www.smileymicros.com as well.

Um, no offense intended, but... The way your question is worded, it sounds like you're at exactly the knowledge level that the Arduino environment is aimed at. The documents above are all aimed at people who already understand quite a bit about microcontroller architectures and assembly languages; it'll be 700 pages of rough going without that background...

westfw
 
Posts: 1711
Joined: Fri Apr 27, 2007 1:01 pm
Location: SF Bay area

Re: AVR commands

by len17 on Thu Feb 18, 2010 7:34 pm

You can also look at the Arduino source code to see how functions like digitalWrite are implemented.

len17
 
Posts: 394
Joined: Sat Mar 14, 2009 7:20 pm

Re: AVR commands

by FazJaxton on Fri Feb 19, 2010 12:16 pm

I think the easiest place to start is to browse the Arduino code online: http://code.google.com/p/arduino/source ... #svn/trunk. There is a search bar you can use to find the functions you're interested in, and then see how they're implemented.

A word of warning: these libraries are written to be efficient and useful for different applications. This means that they are not implemented in the simplest way possible. I looked up serialRead in the library, and it's implemented with a buffer so that several characters can be received before any is read by the program. The simplest way to read the serial port is to have your main program wait forever for a byte to be received, then read it directly. The library way is much better, but more complicated.

As long as you have a little experience with C and some patience, you'll be fine. If you're new to C, it might help to spend a little time becoming familiar with that first.

Another good resource is the arv-libc page. It will help explain some of the functions you see for handling interrupts and other CPU functions. Feel free to post any more questions you have.
FazJaxton
 
Posts: 59
Joined: Mon Sep 28, 2009 2:18 pm
Location: Kansas, USA

Re: AVR commands

by mschiff on Fri Feb 19, 2010 11:59 pm

@FazJaxton:

Thanks for the link to the source codes, thats exactly what I was looking for. I do know C so I think that I will make it through their source code.

My goal was to be able to cut the fat off of the various libraries when aspects of them would not be needed for a specific task. (But I will keep in mind that sometimes the library versions best for the task).


@westfw:

Im looking over the AVR Insruction set and trying to understand as much as I can. How much is assembly used in the actual programming of the device?
-Michael-
mschiff
 
Posts: 26
Joined: Tue Feb 02, 2010 3:35 pm

Re: AVR commands

by len17 on Sat Feb 20, 2010 1:38 am

If you've been using the Arduino software, you've already got the source code for the AVR functions on your computer.

AVR programming is mostly in C, not assembly, from what I've seen anyway. I found the most useful information is the descriptions of the various device control registers, in the "full data sheet" that westfw linked above.

len17
 
Posts: 394
Joined: Sat Mar 14, 2009 7:20 pm

Re: AVR commands

by Entropy on Mon Feb 22, 2010 4:57 pm

mschiff wrote:@FazJaxton:

Thanks for the link to the source codes, thats exactly what I was looking for. I do know C so I think that I will make it through their source code.

My goal was to be able to cut the fat off of the various libraries when aspects of them would not be needed for a specific task. (But I will keep in mind that sometimes the library versions best for the task).


@westfw:

Im looking over the AVR Insruction set and trying to understand as much as I can. How much is assembly used in the actual programming of the device?
-Michael-

It sounds like what you're looking for is to code in straight AVR-GCC - Trim lots of fat without losing your sanity.

It's basically a set of layers of abstraction:
Arduino is layered over AVR-GCC
AVR-GCC outputs AVR machine language code and can output ASM as an intermediary
People who want to squeeze absolute maximum performance out of the AVR will use ASM

Very few people have the need to dive down as far as programming entirely in ASM, or even inlining ASM. AVR-GCC is pretty close as far as efficiency goes.

In my case - I have never used the Arduino environment, and have used AVR-GCC a lot. If you want a good place to start for AVR-GCC programming, look at the avr-libc documentation.
Entropy
 
Posts: 472
Joined: Tue Jan 08, 2008 12:43 am
Location: Owego, NY USA

Re: AVR commands

by westfw on Tue Feb 23, 2010 2:22 am

Im looking over the AVR Insruction set and trying to understand as much as I can. How much is assembly used in the actual programming of the device?

Well, avr-gcc is good enough that you generally shouldn't have to write ANY assembly language. But you asked about the "commands" that went together to make something like digitalWrite(), and that would be the assembly language. If you're already familiar with C, perhaps you asked the wrong question - what you need to know about is the "objects" you work with (using standard C) to effect external events like changing pin values. IO Ports, "Special Function Registers", timers, peripheral hardware, and so on. These are also described in the chip datasheet, but it's perhaps MORE complicated than the assembly language. Also, they tend to be described in terms of the assembly language, which is ... not helpful ... if you were hoping on staying at the C level. (It's worth pointing out that some of the newer processor chips, like the Stellaris ARM chips, are starting to "document" their internals with C, publishing C libraries instead of detailed descriptions of the hardware like you see in an AVR datasheet. This is annoying in a somewhat different way...)

westfw
 
Posts: 1711
Joined: Fri Apr 27, 2007 1:01 pm
Location: SF Bay area

Please be positive and constructive with your questions and comments.