Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

AVR compiling problem

Status
Not open for further replies.

david90

Advanced Member level 1
Joined
May 5, 2004
Messages
423
Helped
9
Reputation
18
Reaction score
4
Trophy points
1,298
Activity points
3,611
print float winavr

i'm trying to compile this code
Code:
//*****************************************************************************
// File Name	: rprintftest.c
// 
// Title		: example usage of rprintf library functions
// Revision		: 1.0
// Notes		:	
// Target MCU	: Atmel AVR series
// Editor Tabs	: 4
// 
// Revision History:
// When			Who			Description of change
// -----------	-----------	-----------------------
// 10-Sep-2002	pstang		Created the program
//*****************************************************************************

 
//----- Include Files ---------------------------------------------------------
#include <avr/io.h>		// include I/O definitions (port names, pin names, etc)
#include <avr/signal.h>	// include "signal" names (interrupt names)
#include <avr/interrupt.h>	// include interrupt support

#include "global.h"		// include our global settings
#include "uart.h"		// include uart function library
#include "rprintf.h"	// include printf function library
#include "timer.h"		// include timer function library (timing, PWM, etc)
#include "vt100.h"		// include VT100 terminal support

void rprintfTest(void);

//----- Begin Code ------------------------------------------------------------
int main(void)
{
	// initialize our libraries
	// initialize the UART (serial port)
	uartInit();
	// set the baud rate of the UART for our debug/reporting output
	uartSetBaudRate(9600);
	// initialize the timer system
	timerInit();

	// initialize rprintf system
	// - use uartSendByte as the output for all rprintf statements
	//   this will cause all rprintf library functions to direct their
	//   output to the uart
	// - rprintf can be made to output to any device which takes characters.
	//   You must write a function which takes an unsigned char as an argument
	//   and then pass this to rprintfInit like this: rprintfInit(YOUR_FUNCTION);
	rprintfInit(uartSendByte);

	// initialize vt100 library
	vt100Init();
	
	// clear the terminal screen
	vt100ClearScreen();
	
	// run the test
	rprintfTest();

	return 0;
}

void rprintfTest(void)
{
	u16 val;
	u08 mydata;
	u08 mystring[10];
	float b;
	u08 small;
	u16 medium;
	u32 big;

	// print a little intro message so we know things are working
	rprintf("\r\nThis is my cool program!\r\n");

	
	rprintf("\r\nWelcome to rprintf Test!\r\n");

	// print single characters
	rprintfChar('H');
	rprintfChar('e');
	rprintfChar('l');
	rprintfChar('l');
	rprintfChar('o');
	// print a constant string stored in FLASH
	rprintfProgStrM(" World!");
	// print a carriage return, line feed combination
	rprintfCRLF();
	// note that using rprintfCRLF() is more memory-efficient than
	// using rprintf("\r\n"), especially if you do it repeatedly

	mystring[0] = 'A';
	mystring[1] = ' ';
	mystring[2] = 'S';
	mystring[3] = 't';
	mystring[4] = 'r';
	mystring[5] = 'i';
	mystring[6] = 'n';
	mystring[7] = 'g';
	mystring[8] = '!';
	mystring[9] = 0;	// null termination

	// print a null-terminated string from RAM
	rprintfStr(mystring);
	rprintfCRLF();

	// print a section of a string from RAM
	// - start at index 2
	// - print 6 characters
	rprintfStrLen(mystring, 2, 6);
	rprintfCRLF();


	val = 24060;
	mydata = 'L';

	// print a decimal number
	rprintf("This is a decimal number: %d\r\n", val);

	// print a hex number
	rprintf("This is a hex number: %x\r\n", mydata);
	
	// print a character
	rprintf("This is a character: %c\r\n", mydata);

	// print hex numbers
	small = 0x12;		// a char
	medium = 0x1234;	// a short
	big = 0x12345678;	// a long

	rprintf("This is a 2-digit hex number (char) : ");
	rprintfu08(small);
	rprintfCRLF();

	rprintf("This is a 4-digit hex number (short): ");
	rprintfu16(medium);
	rprintfCRLF();

	rprintf("This is a 8-digit hex number (long) : ");
	rprintfu32(big);
	rprintfCRLF();

	// print a formatted decimal number
	// - use base 10
	// - use 8 characters
	// - the number is signed [TRUE]
	// - pad with '.' periods
	rprintf("This is a formatted decimal number: ");
	rprintfNum(10, 8, TRUE, '.', val);
	rprintfCRLF();

	b = 1.23456;

	// print a floating point number
	// use 10-digit precision
	
	// NOTE: TO USE rprintfFloat() YOU MUST ENABLE SUPPORT IN global.h
	// use the following in your global.h: #define RPRINTF_FLOAT

	//rprintf("This is a floating point number: ");
	//rprintfFloat(8, b);
	//rprintfCRLF();
}

With this Make file
Code:
# Makefile for AVR function library development and examples
# Author: Pascal Stang
#
# For those who have never heard of makefiles: a makefile is essentially a
# script for compiling your code.  Most C/C++ compilers in the world are
# command line programs and this is even true of programming environments
# which appear to be windows-based (like Microsoft Visual C++).  Although
# you could use AVR-GCC directly from the command line and try to remember
# the compiler options each time, using a makefile keeps you free of this
# tedious task and automates the process.
#
# For those just starting with AVR-GCC and not used to using makefiles,
# I've added some extra comments above several of the makefile fields which
# you will have to deal with.

########### change this lines according to your project ##################
#put the name of the target mcu here (at90s8515, at90s8535, attiny22, atmega603 etc.)
#	MCU = atmega8515
	MCU = atmega163
#	MCU = atmega323
#	MCU = atmega161
#	MCU = atmega128

#put the name of the target file here (without extension)
#  Your "target" file is your C source file that is at the top level of your code.
#  In other words, this is the file which contains your main() function.

	TRG = rprintftest

#put your C sourcefiles here 
#  Here you must list any C source files which are used by your target file.
#  They will be compiled in the order you list them, so it's probably best
#  to list $(TRG).c, your top-level target file, last.

	SRC = $(AVRLIB)/buffer.c $(AVRLIB)/uart.c $(AVRLIB)/rprintf.c $(AVRLIB)/timer.c $(AVRLIB)/vt100.c $(TRG).c

#put additional assembler source file here
#  The ASRC line allows you to list files which contain assembly code/routines that
#  you would like to use from within your C programs.  The assembly code must be
#  written in a special way to be usable as a function from your C code.

	ASRC =

#additional libraries and object files to link
#  Libraries and object files are collections of functions which have already been
#  compiled.  If you have such files, list them here, and you will be able to use
#  use the functions they contain in your target program.

	LIB	=

#additional includes to compile
	INC	= 

#assembler flags
	ASFLAGS = -Wa, -gstabs

#compiler flags
	CPFLAGS	= -g -Os -Wall -Wstrict-prototypes -I$(AVRLIB) -Wa,-ahlms=$(<:.c=.lst)

#linker flags
	LDFLAGS = -Wl,-Map=$(TRG).map,--cref
#	LDFLAGS = -Wl,-Map=$(TRG).map,--cref -lm

	
########### you should not need to change the following line #############
include $(AVRLIB)/make/avrproj_make
		  
###### dependecies, add any dependencies you need here ###################
#  Dependencies tell the compiler which files in your code depend on which
#  other files.  When you change a piece of code, the dependencies allow
#  the compiler to intelligently figure out which files are affected and
#  need to be recompiled.  You should only list the dependencies of *.o 
#  files.  For example: uart.o is the compiled output of uart.c and uart.h
#  and therefore, uart.o "depends" on uart.c and uart.h.  But the code in
#  uart.c also uses information from global.h, so that file should be listed
#  in the dependecies too.  That way, if you alter global.h, uart.o will be
#  recompiled to take into account the changes.

buffer.o		: buffer.c		buffer.h
uart.o		: uart.c			uart.h		global.h
uart2.o		: uart2.c		uart2.h		global.h
rprintf.o	: rprintf.c		rprintf.h
a2d.o			: a2d.c			a2d.h
timer.o		: timer.c		timer.h		global.h
pulse.o		: pulse.c		pulse.h		timer.h	global.h
lcd.o			: lcd.c			lcd.h			global.h
i2c.o			: i2c.c			i2c.h			global.h
spi.o			: spi.c			spi.h			global.h
swpwm.o		: swpwm.c		swpwm.h		global.h
servo.o		: servo.c		servo.h		global.h
swuart.o		: swuart.c		swuart.h		global.h
tsip.o		: tsip.c			tsip.h		global.h
nmea.o		: nmea.c			nmea.h		global.h
vt100.o		: vt100.c		vt100.h		global.h
gps.o			: gps.c			gps.h			global.h
$(TRG).o		: $(TRG).c						global.h

It will work until I change
MCU = atmega163 to MCU = at90s2313
 

at90s2313 uart code

david90 said:
It will work until I change
MCU = atmega163 to MCU = at90s2313

Probably because you can't push an elephant through a mouse wall hole.
I don't know how big is your compiled code, but Atmega163 has 16K flash memory program and AT90S2313 has only 2K.
At first glance rprintftest.c doesn't seems too big. But including library for floating point could overkill 2K memory of AT90S2313.
Don't shoot me if my assumption is wrong.
 

uartsetbaudrate avr-gcc

here is the compiler's message,
> "make.exe" all
avr-gcc -c -g -Os -Wall -Wstrict-prototypes -Ic:\avrlib -Wa,-ahlms=rprintftest.lst -mmcu=at90s2313 -I. rprintftest.c -o rprintftest.o
In file included from rprintftest.c:19:
C:/WinAVR/avr/include/avr/signal.h:36:2: warning: #warning "This header file is obsolete. Use <avr/interrupt.h>."
avr-gcc -c -g -Os -Wall -Wstrict-prototypes -Ic:\avrlib -Wa,-ahlms=c:\avrlib/buffer.lst -mmcu=at90s2313 -I. c:\avrlib/buffer.c -o c:\avrlib/buffer.o
avr-gcc -c -g -Os -Wall -Wstrict-prototypes -Ic:\avrlib -Wa,-ahlms=c:\avrlib/uart.lst -mmcu=at90s2313 -I. c:\avrlib/uart.c -o c:\avrlib/uart.o
In file included from c:\avrlib/uart.c:20:
C:/WinAVR/avr/include/avr/signal.h:36:2: warning: #warning "This header file is obsolete. Use <avr/interrupt.h>."
avr-gcc -c -g -Os -Wall -Wstrict-prototypes -Ic:\avrlib -Wa,-ahlms=c:\avrlib/rprintf.lst -mmcu=at90s2313 -I. c:\avrlib/rprintf.c -o c:\avrlib/rprintf.o
avr-gcc -c -g -Os -Wall -Wstrict-prototypes -Ic:\avrlib -Wa,-ahlms=c:\avrlib/timer.lst -mmcu=at90s2313 -I. c:\avrlib/timer.c -o c:\avrlib/timer.o
In file included from c:\avrlib/timer.c:20:
C:/WinAVR/avr/include/avr/signal.h:36:2: warning: #warning "This header file is obsolete. Use <avr/interrupt.h>."
c:\avrlib/timer.c: In function `timer1PWMInit':
c:\avrlib/timer.c:306: error: `OCR1BH' undeclared (first use in this function)
c:\avrlib/timer.c:306: error: (Each undeclared identifier is reported only once
c:\avrlib/timer.c:306: error: for each function it appears in.)
c:\avrlib/timer.c:307: error: `OCR1BL' undeclared (first use in this function)
c:\avrlib/timer.c: In function `timer1PWMBOn':
c:\avrlib/timer.c:354: error: `COM1B1' undeclared (first use in this function)
c:\avrlib/timer.c:355: error: `COM1B0' undeclared (first use in this function)
c:\avrlib/timer.c: In function `timer1PWMBOff':
c:\avrlib/timer.c:370: error: `COM1B1' undeclared (first use in this function)
c:\avrlib/timer.c:371: error: `COM1B0' undeclared (first use in this function)
c:\avrlib/timer.c: In function `timer1PWMBSet':
c:\avrlib/timer.c:395: error: `OCR1B' undeclared (first use in this function)
c:\avrlib/timer.c: At top level:
c:\avrlib/timer.c:451: warning: `SIG_OUTPUT_COMPARE1B' appears to be a misspelled signal handler
c:\avrlib/timer.c:467: warning: `SIG_OUTPUT_COMPARE2' appears to be a misspelled signal handler
make.exe: *** [c:\avrlib/timer.o] Error 1
rm c:\avrlib/uart.o c:\avrlib/buffer.o c:\avrlib/rprintf.o

> Process Exit Code: 2
> Time Taken: 00:04

If I use the Atmega instead of at90s2313, the errors above would not occur.
 

avrgcc convert to decimal

Well, I'm not a keen on WinAVR compiler, but if it's not a dumb compiler (I'm sure isn't) then definitely it's not enough to mentione MCU = at90s2313 rather than MCU = atmega163.
It must be another declaration to inform the compiler that inside "timerInit();" which invokes timer.c file, OCR1B, COM1B must not be initialized or used since are not present in AT90S2313.
The other warning regarding obsolete header signal.h and better using interrupt.h it's stupid compiler warning because you've just used it but declared after signal.h

Thus, go into c:\avrlib\timer.c and comment out any reference to OCR1B, COM1B which are used but not declared due to MCU = AT90S2313 which removes the header file including the coresponding definitions. This is not a nice solution but at least to try and see if the errors are still raised by makefile utility.
 

avr signal misspelled

The reason this will not compile to the 2313 is the required timer resources are not available on that part. The header file io.h takes the MMCU attribute and the includes the appropriate device header file. IO163.h is included when you select the MEGA163. This header has the required timer variables defined. The IO2313.h file does not have these defines because the resources are not available in that part.

To use any of this code in the 2313, you will have rewrite the timer stuff or pare down the requirements so that it can be eliminated.

--- Steve
 

undeclared first use in this function) avr

Hi,

You can Try IAR C compiler i use it and it works so fine
and you don't have to care about the make file

Fire in The Wire :idea:
 

avrlib uart2 error

banjo right register name and peripheral of at902313 isn't the same as atmega163. however, when you complete to compile this code you can't fit it to at902313. i suggest you to use atmega8 of more when you use avrlib
 

gps.h+avr

The include file signal.h and interrupt.h is actually refer to the same thing that is deal with interrupt vector for MCU. Try delete the the line #include <avr/signal.h> and try compile again.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top