6 Replies Latest reply on Jun 27, 2017 12:26 AM by user_1377889

    Fail to print floating/double number using sprintf

    content.librarian

       Hi all,

         

      I got a long codes which used to calculate some statistical parameters using PSoC MCU. To reserve precision, I tried to print the result using XBee through an UART interface. However, the PSoC doesn't print any floating or double character to the XBee. 

         

      Since it is quite a long code, I will only extract the part which might cause the problem.

         

       ================================================================================

         

      #include <device.h>

         

      #include <string.h>

         

      #include <stdio.h>

         

      #include <stdlib.h>

         

      #include <math.h>

         

      //..............Many other codes.............

         

      char DataBuffer[50] = {'\0'};

         

      int16 array_ADC2[8192]; //Channel for ADC

         
          //..............Many other codes including ADC.............   
         

          //Mean

         

          for(i=0; i<8192; i++)

         

              mean += ((double)array_ADC2[i])/8192;

         

          sprintf(DataBuffer, "Mean: %f\r\n",mean);

         

          UART_PutString(DataBuffer);

         

       ================================================================================

         

      However, one the UART interface, it onlyshows "Mean: " without printing out the double-typed variable. I tried to print it with int and it actually works so perhaps there is some configuration/coding that I missed out?

         

      Thank you very much.