DPRG
DPRG List  



[DPRG] AVR sprintf problem

Subject: [DPRG] AVR sprintf problem
From: Kipton Moravec kip at kdream.com
Date: Tue Jul 18 06:02:10 CDT 2006

You left out some very important details.  Let me guess them.

1. You are using the WinAvr compiler.
2. You did not run Mfile.
3. As a result your linker does not use the printf and scanf library
that supports floating point (the default is no floating point to save
space).

You need to run Mfile. Or go to your makefile find where it says:

----------------------------------------------------
#Additional libraries.

# Minimalistic printf version
PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min

# Floating point printf version (requires MATH_LIB = -lm below)
PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt

PRINTF_LIB = $(PRINTF_LIB_FLOAT) <--- Change yours to look like this

# Minimalistic scanf version
SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min

# Floating point + %[ scanf version (requires MATH_LIB = -lm below)
SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt

SCANF_LIB = $(SCANF_LIB_FLOAT) <--- Change yours to look like this
-------------------------------------------------------------------  

See if that fixes you up.  

I know this from experience. I had the same problem and after a few days
of trying different things thought the compiler was broken, and finally
asked in the AVRfreaks WINAVR forum.

Kip



On Tue, 2006-07-18 at 00:58 -0500, Scott Sumner wrote:
> Hello all,
> 	I'm using the ADC in an Atmega88 to read a voltage and display it on a set
> of 7 segment LEDs.  I'm succesfully reading the ADC because I can output the
> result register directly and the number reflects changes in the
> potentiometer.  However, as soon as I do the math to convert it to voltage
> and attempt to sprintf the decimal value into my string I get a blank
> display.  I'm using a double to store the conversion result and have tried
> %f, %lf, %3.3lf, etc. as the sprintf format string.  Any ideas?
> 
> 	Thanks,
> 	Scott
> 	scott at lighthouse21.com
> 
> _______________________________________________
> DPRGlist mailing list
> DPRGlist at dprg.org
> http://list.dprg.org/mailman/listinfo/dprglist
> 
-- 
Kipton Moravec <kip at kdream.com>


More information about the DPRG mailing list