cancel
Showing results for 
Search instead for 
Did you mean: 

Floating point conversion in STM32f767.

sne_123
Associate III

Hello Everyone,

I am using STM32F767 and have generated code from STM32CubeMX. I am trying to convert a string of hexadecimal to float value, but it seems that the float is not converting the value. I am using Keil IDE UV5 ,and I have tried setting "Floating point hardware" in Target options with "Not used", "Single precision" as well as "Double precision", but nothing seems to work. Am I missing something? or is anything needed to be done so that "float" conversion works?

My code is as follows:-

char val[20];float f;

uint32_t num;

sprintf(val,"%02x%02x%02x%02x",0x43,0x71,0x3E,0xE9);

printf("val is %s\n\r",val);

sscanf(val,"%x",&num);

printf("num %x -- %d\n\r",num,num);

f = *((float*)&num);

f = ((float)num);

printf("float is %.2f\n\r",f);

This prints "float is 1131495145.00" whereas it should be "241.245743"

Help will be appreciated.

Thank you.

1 ACCEPTED SOLUTION

Accepted Solutions

hello

f = ((float)num); takes the value of nun and assign it to f.. So is ok the 1131495145.00

comment out the " f = ((float)num); " and will take the result 241.245743

View solution in original post

2 REPLIES 2

hello

f = ((float)num); takes the value of nun and assign it to f.. So is ok the 1131495145.00

comment out the " f = ((float)num); " and will take the result 241.245743

sne_123
Associate III

@Vangelis Fortounas​ Oh yes it worked !! Thank you so much....