Newbie AVR-GCC example code

Go To Last Post
23 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi, Here's some newbie AVR-GCC example code...

[note this dates from 2004 and may be out of date - in particular the way the Makefile generates dependencies leads to .d files that include DOS pathnames (on Windows) which are not portable to Linux

The recommendation these days would be to always use the Mfile utility (part of WinAVR) to create any Makefile you use]

Attachment(s): 

Assumptio mater errorum est

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I also have some really, really small and basic functions for the absolute beginner here at http://www.users.on.net/~symes/CwithAVR/IntrotoCwithAVR.htm

Will update with more code soon. Updated again today 4/1/05. More to follow.
* 11/01/05 Updated with software I2C routine in AVR-GCC.

*10/2/2005 Updated site with new Mega32 page and an example hardware I2C (TWI) program. Fully commented and explained (I hope:) )

*22/9/05 Update. Added more to the Mega32 category (RTC routines for DS1307). More to come soon.

Last Edited: Thu. Sep 22, 2005 - 11:42 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

hey, dudes, fix the download link =)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

daggerr wrote:
hey, dudes, fix the download link =)

Just rename the linked file as a .zip file :)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

kkempeneers wrote:
Hi, Here's some newbie AVR-GCC example code...

Hi, just tought I would contribute back my changes to you example code. I found bugs in the interrupt driven uart example with the way you hande the queue head and tail. Specifically the way the number of entries in the queue is calculated. The calculation has to change when the tail is above the head (the head has wrapped but the tail not). I also think the way I handle wrapping of the pointers is safer.

A .zip file containing the changed uart.c and uart.h files is attached.

Johan Hartman

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello no_idea,

The problem could be because of the optimization in Makefile. Open the make file and check "opt = " line. If the line is opt = s replace 's' with '0' (zero). Now re-compile your code and check.

Regards

Parthasaradhi Nayani

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Johan Hartman wrote:
kkempeneers wrote:
Hi, Here's some newbie AVR-GCC example code...

Hi, just tought I would contribute back my changes to you example code. I found bugs in the interrupt driven uart example with the way you hande the queue head and tail. Specifically the way the number of entries in the queue is calculated. The calculation has to change when the tail is above the head (the head has wrapped but the tail not). I also think the way I handle wrapping of the pointers is safer.

A .zip file containing the changed uart.c and uart.h files is attached.

Johan Hartman

Please note in the above contributed code - I did not include the main.c file I was using. I enable / disable interrupts in the main.c file. So to make the code work properly for you, you will have to sei() either in the main.c file after calling first_init in uart.c - or put it at the end of first_init.

Johan Hartman

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Johan,

You created the bug yourself when you changed;

rbuf [r_in & RMASK] = c;
r_in++;

in to

rbuf [r_in] = c;
r_in++;
r_in &= RMASK;

Both code segments aren't equivalent... Think about it. Don't take this the wrong way i hessitated for long before posting this reply.
The bufferpointers must count up to 255 for the wrapping to work. Though i don't doubt your solution works, mine takes less flash.

KK

PS. Thanks for the effort, more people should follow your example! We haven't had any fdeviceopen () related questions since the sample code has become a sticky post.

Assumptio mater errorum est

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi.. can i ask if there is a newbie guide to how to actually compile C code and get it onto the chip?

I have a STK500 dev board and either an ATMega16 or an AT90S8515.

Cheers.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

Your question is kind of broad but maybe the below document will help somewhat (as far simulating code and getting it into your chip).

http://www.atmel.com/dyn/resourc...

What have you looked at so far and where are you confused?

Regards,
Steve

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Here is a soft timer example in the academy:
ID: 358

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

kkempeneers wrote:
Hi, Here's some newbie AVR-GCC example code...

Hi, I have a little question, I compiled UART and UART-IntSIO from your examples with WinAvr,
but hex file is to big, it is about 14Kb, each.
I saw in makefile, that you use at90s8515, but it has (I think) 8Kb flash and it can't accept 14kb in flash, how can this works?

(PS. sorry for my bad english, I hope you will understand me :wink:)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The hex file is much larger than the size the code will occupy on the chip.

It expresses each byte of data with 2 ASCII characters. Typically, avr-gcc will store 16 data bytes per record (32 ASCII characters). Plus, you have 12 or 13 control characters (depending on your computer system's 'text mode') per record.

So, for example, 4 kB of compiled code could be split into 256 records, each containing 32 data characters and 12 control characters, adding up to a final Hex file size of approximately 11 kB.

(By the way: This is really an unrelated question, which is inappropriate to have attached to this 'sticky' announcement the way it is. Next time, you'd be better off posting questions like this in a separate thread rather than hijacking an existing one.)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for your answer :D,I'm novice and sorry for the inconvenience from next time i will take care of that :oops:

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Not Newbie sample code but maybe someone would appriciate this; Adam Dunkel's µIP httpd (Webserver) sample application ported to AVR-GCC

Acknowledgements;

Adam Dunkels http://www.sics.se/~adam/uip/
Louis Beaudoin http://www.laskater.com/projects/uipAVR.htm

The tricky part is setting up the filesystem for the Harvard oriented AVR Target. The sample code runs on a M32 at 16MHz.
The server is nothing more nor less than the sample webserver at http://uip-demo.sics.se/

Enjoy,

KK

Attachment(s): 

Assumptio mater errorum est

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

SteveN wrote:
Hi,

Your question is kind of broad but maybe the below document will help somewhat (as far simulating code and getting it into your chip).

http://www.atmel.com/dyn/resourc...

What have you looked at so far and where are you confused?

Regards,
Steve

Hi Steve et al,

Another newbie here. Thanks for the link, but I (and, I suspect, Srosam1) am having problems with getting the GCC compiler to work with Studio. Someone sent me a file called avrgcc_studio.pdf which was written in 2001 and is somewhat out of date.

When I try to compile files I get told:
The system cannot find the file specified.
Could Not Find c:\tmpout.txt

Do you have any suggestion for a more up-to-date Studio/GCC primer or a specific suggestion w.r.t. tmpout.txt?

Thanks!
Allison (outoftune24601)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

AVR Studio version 3 allowed you to invoke external compilers, such as avr-gcc, from within AVR Studio. You could use AVR Studio to create, edit, and compile your C files.

That is not currently possible in version 4 of AVR Studio.

Instead, you have to write and compile your programs separately. You can then use AVR Studio to debug/simulate, and to program your software onto an AVR.

Check the documentation section of WinAVR's webpage on sourceforge for a more recent primer on installing and configuring WinAVR (avr-gcc for Windows) as well as details on creating makefiles and compiling projects.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
i'm a newbie for programming avr...
firs of all sorry for my english (i'm from indonesia ;P)

i want to program my atmega8535 with stk500 like board and using codevisionAVR c compiler...

since i didn't find any book for programming the avr with c code so untill now i'm really confused...

does anyone could help me for giving any list of syntax c codes for avr?

of course i would really thank for the help and if you dont mind for giving me some examle code with lot's of comment....

thanks.... :)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

I know this isn't specifically what you asked for but it is another option.

www.smileymicros.com

"C Programming for Microcontrollers"

Many people here have said this is a great book. (I hope so, I just ordered one myself :-) .)

[edit] Sorry, I just noticed you mentioned Codevision. " Embedded C Programming and the Atmel AVR" by Barnett, Cox & O'Cull. This book is expensive but I have seen many people here say it is a great book also.

Regards,
Steve

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

SteveN wrote:
Many people here have said this is a great book. (I hope so, I just ordered one myself :-) .)

Blush... well ermmm... it's not a great book, just a pretty good book with an attitude and some dumb typos so make sure you look at the errata sheet stuffed in the back.

Smiley

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hey,

Thanks for putting together this package. I am very excited to get up to speed with this stuff.

I don't have a PC, so I am using my mac with avr_gcc and uisp. I seem to be able to compile the code just fine... after I switch the DEBUG variable in the makefile from dwarf-2 to stabs.

But when I load the main.hex file on to my 8515 using uisp through my stk500, I don't seem to get a damned thing!!!

I've tried some other programs sent to me by a freind that work just fine... though they all compile to a file called rom.hex.

I'm sure I am doing something stupid.. I just don't know what! Any ideas?

Bill

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Let's take this to a seperate thread, instead of asking questions to a sticky post.

But to answer your question, drop the uisp package and instead use avrdude:
http://savannah.nongnu.org/proje...

uisp is no longer actively maintained, and avrdude is more mature and works on more platforms including Mac OS X.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

For beginners there is a free book avaialable for programming AVR using WinAVR

MY EXPERIENCE IN PROGRAMMING AVR MICROCONTROLLERS IN C USING WINAVR

You can get the book from
http://groups.yahoo.com/group/bo...

Topic locked