cancel
Showing results for 
Search instead for 
Did you mean: 

usart printf float

aeolia_amha
Associate II
Posted on May 31, 2010 at 05:25

usart printf float

37 REPLIES 37
Posted on May 17, 2011 at 13:52

It has nothing to do with the firmware library!

printf is part of the standard 'C' library and, therefore, is provided by your Compiler - so you need to read your specific Compiler Manual to determine what options it supports, and how to enable things like floating point.

You still haven't said what compiler you are using.

aeolia_amha
Associate II
Posted on May 17, 2011 at 13:52

i've read the keil uvision 3 manual. it says that the floating point support has #include rt_fp.h. After inputing the int to double conversion _dflt, it says that argument is incompatible with corresponding format string conversion.

  printf(''TimeVar of timedisplay =%d'',TimeVar);

  _dflt(TimeVar);

  printf(''\nTimeVar in double=%f'',TimeVar);

For printf %d its working, however when int is converted to double, an error will occur. Also, when we removed  _dflt(TimeVar); , it still didn't execute. Does the _dflt() function can be used in C programming or its only applicable for assembly programming?    

Posted on May 17, 2011 at 13:53

''Does the _dflt() function can be used in C programming or its only applicable for assembly programming?''    

What does the Manual tell you?

A search for _dflt() at 

http://www.keil.com/

 gives no hits at all: 

http://www.keil.com/search.asp?PG=1&PX=1&Q=_dflt

aeolia_amha
Associate II
Posted on May 17, 2011 at 13:53

I searched the net and there is no example of it being used in C. I saw an example using assembly language. If this is the case, is there a way to use float for display and computation?

mov bl _dlft

Posted on May 17, 2011 at 13:53

  printf(''TimeVar of timedisplay =%d'',TimeVar);

  _dflt(TimeVar);

  printf(''\nTimeVar in double=%f'',TimeVar);

You seem to be assuming that _dflt will change the type of the variable;  but it won't - that's not how 'C' works!

_dflt  is a function that will return a float value - the input parameter is not affected!

http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0349b/Cihccjii.html

aeolia_amha
Associate II
Posted on May 17, 2011 at 13:53

You're right, I assumed that doing that will convert the value. I think that it doesn't work in C only in assembly languages. 

What do you mean that the input is not affected, where will it return the value? Is there any way to compute in floating point or double accuracy.

Posted on May 17, 2011 at 13:53

I think you need to spend some time with a 'C' textbook to gain a proper understanding of the 'C' programming language.

int int_variable = 23;  // Define a variable of type 'int',

                        // and initialise it with the value 23

double double_variable; // Define a variable of type 'double',

                        // the value is not initialised.

// Call the function '_dflt' to read the 'int' value from 'int_variable',

// and return the corresponding 'double' value, assigning it to 'double_variable'

double_variable = _dflt( int_variable );

// at this point, 'double_variable' now contains the 'double' value corresponding

// to the 'int' value stored in 'int_variable';

// The type and value of 'int_variable' are unchanged.

This is basic 'C' language stuff - nothing specifically to do with Keil or STM32.

Posted on May 17, 2011 at 13:53

Keil supports floating point, not sure if is part of the MICROLIB, but it is working by default, and I'm doing a whole lot of trig and transcendental work.

Why wouldn't you just use casting? Not that it would provide any useful information as you have no fractional data.

printf(''TimeVar of timedisplay =%d'',TimeVar);

printf(''\nTimeVar in float=%f'',(float)TimeVar);

printf(''\nTimeVar in double=%lf'',(double)TimeVar);

So why exactly do you need floating point to compute the Julian date? If you need the time-of-day you can easily separate that from the seconds to get an integer day number.

Pretty common formula I've used in the past. Googling some of the constants.

http://mth.uct.ac.za/~lab/chap1/chap1.pdf

Page 7

1.3.2 Given the year, month and day of the month, the Julian day is calculated as follows:

Julian = (36525*year)/100 + (306001*(month+1))/10000 + day + 1720981

where month is 13 for Jan, 14 for Feb, 3 for Mar, 4 for Apr etc. For Jan and Feb, the year

is reduced by 1. Write a script which asks for the day, month and year and calculates the

Julian day. All variables must be of integer type. What is the Julian day for 7 Jun 2008? [The

answer is 2454624].

In C

int ComputeJulian(int Day, int Month, int Year)

{

  int JulianDate;

// Month 1-12

// Year 1901-2099, evaluated

  if (Month <= 2)

  {

    Year--;

    Month += 12;

  }

  JulianDate = (36525 * Year) / 100 + (306001 * (Month + 1)) / 10000 + Day + 1720981;

  return(JulianDate);

}

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on May 17, 2011 at 13:53

''Keil supports floating point, not sure if is part of the MICROLIB''

See:

http://www.keil.com/support/man/docs/armlib/armlib_bajdadjh.htm

t1
Associate II
Posted on May 17, 2011 at 13:53

''Apparently you haven't used some of the ST example code with Keil, as 512 bytes of stack is inadequate.''

Correct, I haven't.

''It has nothing to do with the firmware library! printf is part of the standard 'C' library and, therefore..''

Probably, but some chip vendors include their own printf function which will over-ride the compilers library version.