AnsweredAssumed Answered

Float to char array corrupting values

Question asked by DAVID MUSHOW on Aug 3, 2012
Latest reply on Aug 6, 2012 by DAVID MUSHOW

Using CW 10.2, JM60 micro full chip simulation.

 

My code calculates pressures and temperatures from ADC values and outputs them to a display that accepts ascii characters.  Trying to use the sprintf to convert between float and ASCII.  When the sprintf lines execute the result loads into the variable locations correctly, but it also corrupts a lot of other variables.  Guessing I am running into the overflow issue with sprintf, but I thought the format part would have fixed that.  Any suggestions on fixes or alternative methods?

 

 

 

//from header

struct Values
{
float T1;
float T2;
float T3;
float P1;
float P2;
float P3;
};
struct DisplayValues
{
char T1[64];
char T2[64];
char T3[64];
char P1[64];
char P2[64];
char P3[64];
};

 

//from Main.c

struct Values Vals;
struct DisplayValues DispVals;

 

void Load_Display(void)
{
int res;
res = sprintf(DispVals.P1, "%6.3f", Vals.P1);
res = sprintf(DispVals.T1, "%4.1f", Vals.T1);

}

Outcomes