Hi all,
I need help. I need to send a float number via UART but i need a way to convert this number into a string to send character by character. I am using the MSP430F1611 and IAR. I tried to program some codes but I had no success.
I tried the first time to separate directly the integer part and the fractional part but had problems with numbers like 54.0034 because the output of the fractional part was allways 34 and not 0034.
Also I tried to use the function sprintf() but didn't work. I found in the documentation that this function does not support float numbers for the MSP430.
I need to solve this problem so i made the code below....I think it is easy to understand. I want to separate the float number in different digits like this: 345.678 ==> "3" "4" "5" "." "6" "7" "8" and send the diferent numbers via UART. I programed this code with DevC software and it worked perfectly, quite the opposite with IAR. It doesn't work with IAR. I know that this code has some restrictions like that i can use only three integers and three decimals but i don't get any other idea about how to do this. It should be a simple problem but i think that it is defeating me...
Anybody can help me?, maybe telling me what is wrong with my code, or with other ideas, or with any other code to send a float via UART with a MSP430...
static void SendValue(float data)
{
static int number;
static char digits[7]={0,0,0,0,0,0,0};
static int i=0;
number = abs(data*1000);
digits[6]= (number % 10) + 48; //add 48 for the corresponding ASCII number
number = number/10;
digits[5]= numero % 10 + 48;
number = number/10;
digits[4]= nnumber % 10 + 48;
number = number/10;
digits[3]= 46; //"."
digits[2]= number % 10 + 48;
number = number/10;
digits[1]= number % 10 + 48;
number = number/10;
digits[0]= number % 10 + 48;
//number = number/10;
if (data <0)
{ TXBUF0 = 45; //"-"
while (!(IFG1 & UTXIFG0));
}
for(i=0; i<7 ; i++)
{
TXBUF0 = (digits[i]);
while (!(IFG1 & UTXIFG0));
}
}
I hope you can help me.Thank you very much for your help in advance.
Greetings
Alejos