NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Microcontroller Programming » Problem with using Math.h atan2(Y, X)

May 28, 2011
by Ralphxyz
Ralphxyz's Avatar

This is in conjunction with my I2C Compass project:

Here is my code:

#include <math.h>
X = ((Xmsb <<8) | Xlsb);
Y = ((Ymsb <<8) | Ylsb);

uint16_t Rads;

Rads = atan2(Y, X)*180/3.14;
//Rads = atan(Y/X)*180/3.14;     
//Rads = 1123;   // this works!!

fprintf_P(&lcd_stream, PSTR("Radians are: %.2u"), Rads);

Here is the error.

make -C ../libnerdkits
make[1]: Nothing to be done for `all'.
avr-gcc -g -Os -Wall -mmcu=atmega328p  -o ../libnerdkits/twimaster.c ../libnerdkits/twimaster.o -c 
avr-gcc: ../libnerdkits/twimaster.o: linker input file unused because linking not done
avr-gcc -g -Os -Wall -mmcu=atmega328p  -Wl,-u,vfprintf -lprintf_flt -Wl,-u,vfscanf -lscanf_flt -lm -o Compass.o Compass.c ../libnerdkits/delay.o ../libnerdkits/lcd.o ../libnerdkits/uart.o ../libnerdkits/twimaster.o
/usr/local/CrossPack-AVR-20100115/lib/gcc/avr/4.3.3/../../../../avr/lib/avr5/libc.a(inverse.o):../../../libm/fplib/inverse.S:50: relocation truncated to fit: R_AVR_13_PCREL against symbol `__divsf3' defined in .text section in /usr/local/CrossPack-AVR-20100115/lib/gcc/avr/4.3.3/avr5/libgcc.a(_div_sf.o)
make: *** [Compass.hex] Error 1
miniMac:compass Me$

I am using my Mac mini OS X 10.6.7 with avr-gcc.


May 29, 2011
by Ralphxyz
Ralphxyz's Avatar

Well clawson over at AVRfreakshad the answer.

It was the -lm flag in the Makefile!

Here is the modified Makefile:

GCCFLAGS=-g -Os -Wall -mmcu=atmega328p 
LINKFLAGS=-Wl,-u,vfprintf -lprintf_flt -Wl,-u,vfscanf -lscanf_flt #-lm
AVRDUDEFLAGS= -vvv -c avr109 -p m328p -F -b 115200 -P /dev/cu.PL2303-0000101D # USB1
ProjectName = Accel

LINKOBJECTS=../libnerdkits/delay.o ../libnerdkits/lcd.o ../libnerdkits/uart.o -lm

all:    $(ProjectName)-upload

$(ProjectName).hex: $(ProjectName).c
    make -C ../libnerdkits
    avr-gcc ${GCCFLAGS} ${LINKFLAGS} -o $(ProjectName).o $(ProjectName).c ${LINKOBJECTS}
    avr-objcopy -j .text -O ihex $(ProjectName).o $(ProjectName).hex

$(ProjectName).ass: $(ProjectName).hex
    avr-objdump -S -d $(ProjectName).o > $(ProjectName).ass

$(ProjectName)-upload:  $(ProjectName).hex
    avrdude ${AVRDUDEFLAGS} -U flash:w:$(ProjectName).hex:a

Now to get the Xlsb and Ylsb figured out.


Post a Reply

Please log in to post a reply.

Did you know that you can generate hundreds of volts AC from your microcontroller with a little bit of circuitry? Learn more...