AnsweredAssumed Answered

float type value is not sent through uart...

Question asked by Karthickph on Apr 17, 2014
Latest reply on Apr 18, 2014 by MMA

Hi,  I'm working ADuC7060 microconverter and developing a code which should show the result in float.  For this I'm converting a unsigned char byte in float and adding it with a real float value and trying to send it through UART the added value in float type.  However, I'm not seen any of the results, to my surprise when it is %d the results are seen.  I don't what's wrong with this code, can you please let know if you find any wrong in this below code;

 

unsigned char rx_byte[2] = {0,0};

unsigned char szTemp[64] = "";     // Used to store ADC0 result before printing to UART
unsigned int nLen =0;
unsigned char i =0;

float fracaccuracy(unsigned char low_byte);
unsigned char addonvalue =0;
float accuracy =0.0;
float fraction =0;
float temperature =0;
unsigned char temp_msb =0;
float temperature1 =0;

main()

{

while(1){

    fraction = fracaccuracy(rx_byte[1]);
    temp_msb = (unsigned char)rx_byte[0];
    temperature = (float)((float)temp_msb + fraction);
    temperature1 = temperature;
       sprintf ( (char*)szTemp, "fraction =%f\n\r", temperature);// Send the Result to the UART

        nLen = strlen((char*)szTemp);
            for ( i = 0 ; i < nLen ; i++ )
           {
              COMTX = szTemp[i];
         while ((COMSTA0 & 0x40) == 0x00)   // Wait for Tx buffer empty bit to be set
             {
             }             
        }

}

 

float fracaccuracy(unsigned char low_byte)

{

     if ((low_byte<=240) && (low_byte!=0))

     {

      accuracy =0;

      addonvalue =0;

      do

      {

      accuracy = 0.0625 + accuracy;

      addonvalue+= 16;

      }

      while(low_byte >addonvalue);     

     }

     else

      return 0;

return accuracy;

}

 

Regards,

Karthick

Outcomes