Skip to main content
sne_123
Associate III
Feb 1, 2021 7:01 AM UTC
Solved

Floating point conversion in STM32f767.

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.

This topic has been closed for replies.
Vangelis Fortounas
Associate II
Feb 1, 2021 11:25 PM UTC

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

2 replies

Vangelis Fortounas
Associate II
Feb 1, 2021 11:25 PM UTC

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
sne_123Author
Associate III
Feb 2, 2021 4:24 AM UTC

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