1

I have the following code snippet:

#include "contiki.h"
#include <stdio.h> /* For printf() */

PROCESS(calc_process, "calc process");
AUTOSTART_PROCESSES(&calc_process);

PROCESS_THREAD(calc_process, ev, data)
{
 double  dec=13.2, res=0, div=3.2;

  PROCESS_BEGIN();

res=dec+div;

printf("%f",res);


  PROCESS_END();
}

After uploading the above code in Tmote sky platform using the command

make TARGET=sky calc.upload, the program will be loaded to the mote (there is no error). Then login to the mote using make login TARGET=sky, the following output is displayed....

OUPUT:

**Rime started with address 4.0 MAC 04:00:00:00:00:00:00:00 Contiki 2.7 started. Node id is set to 4. CSMA ContikiMAC, channel check rate 8 Hz, radio channel 26 Starting 'calc process'

%f**

How can I get the correct value?

Thanks

siju koshy
  • 21
  • 3
  • 2
    possible duplicate of [printf support for MSP430 micro-controller](http://stackoverflow.com/questions/12545317/printf-support-for-msp430-micro-controller) – kfx Nov 10 '14 at 13:15

1 Answers1

0

It is not floating point calculation support that you need - you have that already. What is missing is floating point support within printf(). That is to say that res will be calculated correctly, but printf() does not support its display.

Because it requires a relatively large amount of code, many microcontroller targeted libraries omit floating point support in stdio. There may be a library build option to include floating point support - refer to the library documentation.

You might do well to ask a question about the specific calculation necessary, and how it might be done using integer or fixed point arithmetic. Alternatively you might write your own floating point display as described here: How to print floating point value using putchar? for example.

Community
  • 1
  • 1
Clifford
  • 88,407
  • 13
  • 85
  • 165