用STM32F103VET6flash存储float变量,读取时只有整数部分。代码如下:往flash写13.12,读出来DATAW[0]显示13.0。解决送ST金币!
#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;
} |