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 » different results of printf_P between MCU's

October 19, 2012
by fishberg5051
fishberg5051's Avatar

hello all!

quick question of how an MCU might handle the "printf_P" differently. I'm using a 1284P and I've been playing around with the temp sensor project to read data from the LM34 sensor. Upon obtaining my result and trying to print the result through the uart using the following:

double val = GetTemp();
printf_P(PSTR("Temp = %lf\r\n"),val);

that is printing out: "Temp = ?" I am most likely doing something incorrectly or have something set incorrectly but not sure where to check for something like this. When I was using the 168/328 this worked fine. I even tried a simple example from the tutorials:

double pi = 3.14159;
printf_P(PSTR("I like %lf"),pi);

and this results in "I like ?".

Does anyone have any ideas of what I might look into. I can get around it for now but I'd like to know why it's doing this.

Thank you.
October 20, 2012
by esoderberg
esoderberg's Avatar

Fish,

I saw similar results when I switched to using Atmel Studio 6 vice Notepad and manually generated Makefiles. My problem was that the same set of code I was using did not compile the same in Studio 6 as when I used the Nerdkit standard Makefile. When I added the LINKFLAGS below to the Studio 6 compiling instructions it worked, so you may want to check your Makefile as a potential fix.

LINKFLAGS=-Wl,-u,vfprintf -lprintf_flt -Wl,-u,vfscanf -lscanf_flt

Eric

October 20, 2012
by fishberg5051
fishberg5051's Avatar

Hey Eric,

where exactly in studio 6 did you add that? Are you using an external makefile when you build? I'm thinking this might be my issue as well for I'm using studio 6 vs. the notepad/manually generated makefiles. If you could provide the specific location where to place that linkflag comment I'd be very grateful!

Thank you very much.

October 20, 2012
by fishberg5051
fishberg5051's Avatar

Hey Eric,

Nevermind I looked around for a little longer and was able to find it. In studio 6, project -> Properties -> Toolchain -> AVR/GNU Linker -> Miscellaneous -> there is an option for "other linker flags" and I entered:

-Wl,-u,vfprintf -lprintf_flt -lm

and that seemed to work! Thanks so much for the info!

October 20, 2012
by esoderberg
esoderberg's Avatar

Fish,

Yep, that's exactly where I put it as well; I guess I should have posted the more explicit Studio 6 instructions the way you did, but I was going on the assumption that you were using your own Makefile. I'm glad someone else here on the NK boards is jumping on the Studio 6 bandwagon too to help work through these issues.

Eric

October 20, 2012
by fishberg5051
fishberg5051's Avatar

Hey Eric,

ya I've been using studio 6 for this project. For work I write 90% of my projects in c# so visual studio has been my main ide for quite some time so this is familiar to me at least. I'm not the strongest at C however so any tips or tricks that the ide shares me with I like :D

Thanks again for the help.

Post a Reply

Please log in to post a reply.

Did you know that Pulse Width Modulation (PWM) can be used to control the speed of a motor digitally? Learn more...