当前位置:网站首页>STM32 stores float data in flash

STM32 stores float data in flash

2022-06-25 12:39:00 Who am I?

Float Type numbers are used in computers 4 Byte store , follow IEEE-754 Format standard :

Float data The symbolic part (S) The base part (M) Index part (E)
explain

0 Express positive

1 Negative

Use binary numbers to represent the actual value of this floating point number , The base part is actually occupied 24 bit A value of , But the highest bit is not stored , Share in storage 23 bit Science and Technology Law .

  Occupy 8 bit Binary number of , The range of values that can be expressed is 0~255. Because the index can be positive or negative , So, in accordance with the IEEE Specify the calculated index minus 127 Is the real index ,float The real range of the type of index is -127 To 128.

So the format is :SEEE EEEE EMMM MMMM MMMM MMMM MMMM MMMM

stay flash Medium access float There are two ways of data , The first way to use pointers

 hold float Data stored in flash in 

float data;

uint32_t temp;

temp = *(uint32_t *)&data;

Flash_WriteWordData(Flash_Save_Adder, temp);


 from flash Read it out 

Flash_ReadWordData(Flash_Write_Adder, temp);

data = *(float *)&temp;

Second common body , Use the common body to share a section of memory for storage

float data;
union
{

    float a;

    uint32_t b;

}temp;

temp.a = data;

Flash_WriteWordData(Flash_Save_Adder, temp.b);


 from flash Read it out 

Flash_ReadWordData(Flash_Write_Adder, temp.b);

data = temp.a;



Link to the original text :https://blog.csdn.net/qq_41836400/article/details/121964054

原网站

版权声明
本文为[Who am I?]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/176/202206251207198265.html