Forum Menu




 


Log in Problems?
New User? Sign Up!
AVR Freaks Forum Index

Post new topic   This topic is locked: you cannot edit posts or make replies.
View previous topic Printable version Log in to check your private messages View next topic
Author Message
kkempeneers
PostPosted: Nov 24, 2004 - 10:32 AM
Hangaround


Joined: Dec 26, 2002
Posts: 158
Location: Belgium, Europe

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]

_________________
Greatness isn't measured by achievement, but by persistence after failure.
 
 View user's profile Send private message Send e-mail  
Reply with quote Back to top
Dingo_aus
PostPosted: Dec 31, 2004 - 02:18 PM
Resident


Joined: Sep 18, 2004
Posts: 643
Location: Brisbane, Australia

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.

_________________
Dingo_aus
http://www.users.on.net/~symes/


Last edited by Dingo_aus on Sep 22, 2005 - 12:42 PM; edited 3 times in total
 
 View user's profile Send private message  
Reply with quote Back to top
daggerr
PostPosted: Jan 19, 2005 - 04:08 PM
Newbie


Joined: Dec 25, 2001
Posts: 9


hey, dudes, fix the download link =)
 
 View user's profile Send private message  
Reply with quote Back to top
nleahcim
PostPosted: Jan 30, 2005 - 01:57 AM
Raving lunatic


Joined: Feb 19, 2003
Posts: 2233
Location: Seattle, WA

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


Just rename the linked file as a .zip file Smile
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
no_idea
PostPosted: Feb 04, 2005 - 10:46 AM
Newbie


Joined: Feb 04, 2005
Posts: 14


Hey I am a newbie tryin to get the hang of serial programming. I am tryin to read the output of a temp sensor (thermistor), put it though an ADC of Port A and make that value appear on a pin of Port B. However with the code below the pin on port B only ouptuts 5V. Any advice or hints would be greatly appreciated.Please!!! Am using the atmega8515

#include <avr/io.h>
#include <avr/delay.h>

int main (void)
{
DDRB = 0xff; //sets all bits of port B for output
DDRA = 0xfe; //sets one bits of portA to be an input
while(1)
{
PORTB= PINA;


}
return 1;
}
 
 View user's profile Send private message  
Reply with quote Back to top
Johan Hartman
PostPosted: Feb 15, 2005 - 07:04 PM
Wannabe


Joined: Jul 18, 2004
Posts: 59
Location: South Africa

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
 
 View user's profile Send private message  
Reply with quote Back to top
Nayani P
PostPosted: Feb 16, 2005 - 04:57 PM
Wannabe


Joined: Mar 30, 2004
Posts: 97
Location: Hyderabad. India

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
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
Johan Hartman
PostPosted: Mar 07, 2005 - 08:12 PM
Wannabe


Joined: Jul 18, 2004
Posts: 59
Location: South Africa

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
 
 View user's profile Send private message  
Reply with quote Back to top
kkempeneers
PostPosted: Mar 14, 2005 - 04:36 PM
Hangaround


Joined: Dec 26, 2002
Posts: 158
Location: Belgium, Europe

Johan,

You created the bug yourself when you changed;
Code:

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

in to
Code:

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.

_________________
Greatness isn't measured by achievement, but by persistence after failure.
 
 View user's profile Send private message Send e-mail  
Reply with quote Back to top
Srosam1
PostPosted: Mar 28, 2005 - 10:13 AM
Rookie


Joined: Sep 01, 2004
Posts: 24
Location: UK, Essex

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.
 
 View user's profile Send private message  
Reply with quote Back to top
SteveN
PostPosted: Mar 28, 2005 - 03:09 PM
Raving lunatic


Joined: Nov 14, 2001
Posts: 3438
Location: Charlottesville, VA USA

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/resources/prod ... novice.pdf

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

Regards,
Steve
 
 View user's profile Send private message  
Reply with quote Back to top
feralbeagle
PostPosted: May 28, 2005 - 04:20 AM
Hangaround


Joined: Dec 30, 2004
Posts: 134


Here is a soft timer example in the academy:
ID: 358
 
 View user's profile Send private message  
Reply with quote Back to top
slavko
PostPosted: May 31, 2005 - 07:37 PM
Hangaround


Joined: May 17, 2005
Posts: 165


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)
 
 View user's profile Send private message  
Reply with quote Back to top
lfmorrison
PostPosted: May 31, 2005 - 08:12 PM
Raving lunatic


Joined: Dec 08, 2004
Posts: 4719
Location: Nova Scotia, Canada

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.)
 
 View user's profile Send private message  
Reply with quote Back to top
slavko
PostPosted: May 31, 2005 - 09:10 PM
Hangaround


Joined: May 17, 2005
Posts: 165


Thanks for your answer Very Happy,I'm novice and sorry for the inconvenience from next time i will take care of that Embarassed
 
 View user's profile Send private message  
Reply with quote Back to top
kkempeneers
PostPosted: Jul 03, 2005 - 12:03 PM
Hangaround


Joined: Dec 26, 2002
Posts: 158
Location: Belgium, Europe

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

_________________
Greatness isn't measured by achievement, but by persistence after failure.
 
 View user's profile Send private message Send e-mail  
Reply with quote Back to top
outoftune24601
PostPosted: Aug 11, 2005 - 05:53 PM
Newbie


Joined: May 25, 2005
Posts: 1


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/resources/prod ... novice.pdf

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)
 
 View user's profile Send private message  
Reply with quote Back to top
lfmorrison
PostPosted: Aug 11, 2005 - 06:49 PM
Raving lunatic


Joined: Dec 08, 2004
Posts: 4719
Location: Nova Scotia, Canada

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.
 
 View user's profile Send private message  
Reply with quote Back to top
agfa
PostPosted: Sep 09, 2005 - 09:46 PM
Newbie


Joined: Sep 09, 2005
Posts: 2


[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.... Smile
 
 View user's profile Send private message  
Reply with quote Back to top
SteveN
PostPosted: Sep 10, 2005 - 04:20 PM
Raving lunatic


Joined: Nov 14, 2001
Posts: 3438
Location: Charlottesville, VA USA

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 Smile .)

[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
 
 View user's profile Send private message  
Reply with quote Back to top
smileymicros
PostPosted: Sep 10, 2005 - 05:29 PM
Raving lunatic


Joined: Nov 17, 2004
Posts: 6137
Location: Great Smokey Mountains.

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


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

_________________
FREE TUTORIAL: 'Quick Start Guide for Using the WinAVR C Compiler with ATMEL's AVR Butterfly' AVAILABLE AT: http://www.smileymicros.com
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
SwarfEye
PostPosted: Jan 08, 2006 - 10:12 PM
Hangaround


Joined: Jan 08, 2006
Posts: 201
Location: San Francisco, CA

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
 
 View user's profile Send private message  
Reply with quote Back to top
EW
PostPosted: Jan 09, 2006 - 02:58 AM
Raving lunatic


Joined: Mar 01, 2001
Posts: 4953
Location: Rocky Mountains

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/projects/avrdude

uisp is no longer actively maintained, and avrdude is more mature and works on more platforms including Mac OS X.
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
codeman_tronix
PostPosted: May 07, 2006 - 04:43 PM
Wannabe


Joined: Feb 22, 2006
Posts: 65


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/booksbybibin/
 
 View user's profile Send private message  
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT + 1 Hour
Post new topic   This topic is locked: you cannot edit posts or make replies.
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2006 The PNphpBB Group
Credits