用
STM32F103VET6flash存储float变量,读取时只有整数部分。代码如下:往flash写13.12,读出来DATAW[0]显示13.0。
#define FLASH_PAGE_SIZE ((uint32_t)0x00000800) /* FLASH Page Size */
#define FLASH_USER_START_ADDR ((uint32_t)0x0803F800) /* Start @ of user Flash area */
#define FLASH_USER_END_ADDR ((uint32_t)0x0803FFFF) /* End @ of user Flash area */
void Save_factory_parameter()
{
uint32_t Addr = FLASH_USER_START_ADDR , i; //FLASH_USER_START_ADDR的地址留给出厂值设置标志位用的
FLASH_Unlock();
FLASH_ClearFlag(FLASH_FLAG_EOP | FLASH_FLAG_PGERR | FLASH_FLAG_WRPRTERR);
while( FLASH_ErasePage(FLASH_USER_START_ADDR ) != FLASH_COMPLETE );
while( FLASH_ProgramWord( Addr , 13.12 ) != FLASH_COMPLETE ) ;
FLASH_Lock();
}
void Read_factory_parameter()
{
uint32_t Addr = FLASH_USER_START_ADDR ;
DATAW[0] = *(__IO uint32_t *)Addr;
}
{
unsigned int hexvalue;//4 byte
float floatvalue;//4 byte
};
存储读取时用hexvalue成员,
当float用时用floatvalue成员。
用联合体来做,我等会试一下,谢谢帮忙
一周热门 更多>