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 » fprintf_P not working properly in AVRStudio 4.18

March 04, 2010
by xc2rx
xc2rx's Avatar

Hi,

I am trying to run in AVRStudio the "tempsensor" program that came with the nerdkits. So far I got it to compiled in AVRStudio, uploaded, and running on the chip. One thing that is not working is the fprintf_P function:

fprintf_P(&lcd_stream, PSTR("Temperature: %.2f"), temp_avg);

What I'm getting on the LCD is "Temperature: ?*F". Somehow %.2f is not getting replaced with temp_avg. I compiled the program in AVRStudio and uploaded the .hex file onto the chip using AVRDude (same codes I got from the makefile that came with the nerdkits for the avrdude section). Everything works fine if I compile + upload using the makefile that came with the nerdkits for that project. Something is telling me that I am missing something when I compiled the project in AVRStudio. Any hint?

Thanks!

March 05, 2010
by xc2rx
xc2rx's Avatar

Hi again all,

I read a couple of tutorials and they said it could be because the static string might be stored in FLASH memory and the double datatype that i'm trying to append to the string might be stored in SRAM. How do I know which is store in which and why does it matter? Maybe a better question is, how can you tell and how do you declare vars in each memory type (eg: flash, sram, eeprom, etc.)? Would be great if you all can help me understand this. Thank you!

March 05, 2010
by pbfy0
pbfy0's Avatar

flash is

PROGMEM *variable type* *variable name*

eeprom is

EEMEM *variable type* *variable name*

sram is the default, so just

*variable type* *variable name*
March 05, 2010
by xc2rx
xc2rx's Avatar

Still not helping. Please advise me on the question regarding fprintf_P function. Thanks!

March 05, 2010
by hevans
(NerdKits Staff)

hevans's Avatar

Hi xc2rx,

I think that error is happening because of an old version of avr-libc. It appears that AVRStudio might be compiling against a different version of the library than the avr-gcc you are getting at through the command line. I'm actually not familiar with AVRStudio so, I'm sorry I can't be much help, but if you poke around you might be able to find which avr-gcc AVRStudio is using, and either update that or make it point to the one that is installed with WinAVR. Hope that helps.

Humberto

March 05, 2010
by xc2rx
xc2rx's Avatar

Hi,

Thanks for replying to my question. I was using version 20090301 but I just downloaded the newest version, v20100110, and that still didn't work. I am getting the same result. Any clue?

Post a Reply

Please log in to post a reply.

Did you know that NerdKits has been featured on Slashdot, Hack A Day, Hacked Gadgets, the MAKE blog, and other DIY-oriented websites? Learn more...