Society of Robots - Robot Forum

Software => Software => Topic started by: Kirk on September 02, 2008, 10:38:42 PM

Title: UART compile errors
Post by: Kirk on September 02, 2008, 10:38:42 PM
Greetings,
I am trying to run the UART on an ATmega8 with a 16MHz crystal. (arduino board) using WINAVR.
so I am attempting to get the example in
http://www.societyofrobots.com/microcontroller_uart_50_robot.shtml
running.

I am getting the following errors. (which I abbreviate)
My Documents\AVR\LMR-UART2/main.c:79: undefined reference to `uartInit'
My Documents\AVR\LMR-UART2/main.c:80: undefined reference to `uartSetBaudRate'
My Documents\AVR\LMR-UART2/main.c:81: undefined reference to `uartSendByte'
and more

I have included the files as in the tutorial.  I even tried miss spelling a file name.  This give a different (file not found) error message.

The UART will talk to the terminal in the Arduino environment.
I can make the UART work one character at a time by loading a character in the UDR register.

So it seems that this is some deficiency in my understanding of AVRlib and the compiler messages.

Thanks for any help!
Kirk
Title: Re: UART compile errors
Post by: pomprocker on September 02, 2008, 10:46:24 PM
include it (uart.c) in your makefile SRC

put uart.c and uart.h in your project folder

include uart.h somewhere in your code
Title: Re: UART compile errors
Post by: Kirk on September 03, 2008, 08:19:29 PM
Ok Cool it works.  BUT WHY.
Other libraries work when included in the program
Other libraries work while in other directories (if you put EXTRAINCDIRS = in the makefile)
Other libraries only need the .h file included

What is different about the AVRLib files?
What other tricks will I need?

And thanks so much for the help my program development is back on track.

Kirk
Title: Re: UART compile errors
Post by: Webbot on September 03, 2008, 08:37:43 PM
Well I guess the answer is  you need an idea on how the  C compiler works vs the linker

When you include a '.h' file, which can also include other '.h' files, then sometimes the '.h' file contains all of the code that is required - as if you included the source code into your program.  In which case the compiler has all the source code to compile.

However: there are times when the code is quite big and complex (such as dealing with interrupts to send/receive data via the UART). In which case the '.h' program just defines the names and signatures of the UART code. This allows the compiler to compile the program  but you then need to include the corresponding '.c' program that contains the code that does the actual work.

This isn't an AVR, micro-controller 'thing' - its the way that C works.
Title: Re: UART compile errors
Post by: Kirk on September 03, 2008, 10:04:36 PM
OK I mostly understand the include process.  Part of my problem is that AVRlib does not protect against multiple includes and generates a big pile of errors if you do.

What I do not understand at all is why if I include a file (in main.c for instance) it behaves differently than if it is added to the SRC line of makefile.   AND what has me puzzled is how will I know how to include the files.  AND how does Admin make it work in the tutorial?

Thanks
Kirk

PS Can anyone recomende some reading on linker concepts and perhaps a primer on Make.
Title: Re: UART compile errors
Post by: Admin on September 04, 2008, 07:53:27 PM
Quote
AND how does Admin make it work in the tutorial?
Read the first three sections at the very top ;D
http://www.societyofrobots.com/microcontroller_uart_50_robot.shtml