前几天一直再寻找STM32L1系列内部EEPROM存储数据程序,用FLASH模拟EEPROM太复杂了,正合适选择的系列有内部eeprom,和大家分享一下,已经测试过的。
#include "stm32l1xx.h"
#include "main.h"
#define EEPROM_BASE_ADDR 0x08080000
//#define EEPROM_BYTE_SIZE 0x0FFF
void Eeprom_Write_Byte(u32 Start_Address,u8 Data_Value);
u8 Eeprom_Read_Byte(u32 Read_Address);
void Eeprom_Write_Byte(u32 Start_Address,u8 Data_Value)
{
u32 Address =0;
Address = EEPROM_BASE_ADDR+Start_Address;
if(IS_FLASH_DATA_ADDRESS(Address))
{
DATA_EEPROM_Unlock(); //设备解锁
while(FLASH_GetStatus()!=FLASH_COMPLETE);
DATA_EEPROM_ProgramByte(Address,Data_Value);
DATA_EEPROM_Lock();//设备上锁
}
}
u8 Eeprom_Read_Byte(u32 Read_Address)
{
u32 Address =0;
Address = EEPROM_BASE_ADDR+Read_Address;
u8 tmp=0;
if(IS_FLASH_DATA_ADDRESS(Address))
{
DATA_EEPROM_Unlock(); //设备解锁
while(FLASH_GetStatus()==FLASH_BUSY);
tmp=*(__IO uint8_t*)Address;
DATA_EEPROM_Lock();//设备上锁
}
return tmp;
}
|