打印
[STM8]

IAR STM8 1.2 直接使用__eeprom关键字访问EEPROM

[复制链接]
7180|4
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
CC2530|  楼主 | 2011-3-21 22:41 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式
IAR STM8 1.2 直接使用__eeprom关键字访问EEPROM
STM8L15X:
#include "stm8l15x_conf.h"
void __eeprom_write_8(unsigned short addr_eep,unsigned char data)
{
  FLASH_WaitForLastOperation(FLASH_MemType_Data);  
  FLASH_Unlock(FLASH_MemType_Data);
  
  FLASH_ProgramByte(addr_eep, data);
  
  FLASH_WaitForLastOperation(FLASH_MemType_Data);
  FLASH_Lock(FLASH_MemType_Data);  
}
void __eeprom_write_16(unsigned short addr_eep,unsigned short data)
{
  FLASH_WaitForLastOperation(FLASH_MemType_Data);  
  FLASH_Unlock(FLASH_MemType_Data);
  
  FLASH_ProgramByte(addr_eep,   data/256);
  FLASH_WaitForLastOperation(FLASH_MemType_Data);
  
  FLASH_ProgramByte(addr_eep+1, data%256);
  FLASH_WaitForLastOperation(FLASH_MemType_Data);
  
  FLASH_Lock(FLASH_MemType_Data);  
}
void __eeprom_write_32(unsigned short addr_eep,unsigned long data)
{
  FLASH_WaitForLastOperation(FLASH_MemType_Data);  
  FLASH_Unlock(FLASH_MemType_Data);
  
  FLASH_ProgramByte(addr_eep,   (unsigned char)(data>>24));
  FLASH_WaitForLastOperation(FLASH_MemType_Data);
  
  FLASH_ProgramByte(addr_eep+1, (unsigned char)(data>>16));
  FLASH_WaitForLastOperation(FLASH_MemType_Data);
  
  FLASH_ProgramByte(addr_eep+2,   (unsigned char)(data>>8));
  FLASH_WaitForLastOperation(FLASH_MemType_Data);
  
  FLASH_ProgramByte(addr_eep+3, (unsigned char)(data>>0));
  FLASH_WaitForLastOperation(FLASH_MemType_Data);
  
  FLASH_Lock(FLASH_MemType_Data);  
}

void __eeprom_write_many(unsigned short addr_eep,unsigned short size,unsigned short dummy,unsigned short addr_ram)
{
  
  FLASH_WaitForLastOperation(FLASH_MemType_Data);  
  FLASH_Unlock(FLASH_MemType_Data);
  
  for(unsigned short i=0;i<size;i++)
  {
     FLASH_ProgramByte(addr_eep+i,   *((unsigned char *)(addr_ram)+i));
     FLASH_WaitForLastOperation(FLASH_MemType_Data);
  }
  
  
  FLASH_Lock(FLASH_MemType_Data);  
  
}

STM8S:
#include "stm8s_conf.h"
void __eeprom_write_8(unsigned short addr_eep,unsigned char data)
{
  FLASH_WaitForLastOperation(FLASH_MEMTYPE_DATA);  
  FLASH_Unlock(FLASH_MEMTYPE_DATA);
  
  FLASH_ProgramByte(addr_eep, data);
  
  FLASH_WaitForLastOperation(FLASH_MEMTYPE_DATA);
  FLASH_Lock(FLASH_MEMTYPE_DATA);  
}
void __eeprom_write_16(unsigned short addr_eep,unsigned short data)
{
  FLASH_WaitForLastOperation(FLASH_MEMTYPE_DATA);  
  FLASH_Unlock(FLASH_MEMTYPE_DATA);
  
  FLASH_ProgramByte(addr_eep,   data/256);
  FLASH_WaitForLastOperation(FLASH_MEMTYPE_DATA);
  
  FLASH_ProgramByte(addr_eep+1, data%256);
  FLASH_WaitForLastOperation(FLASH_MEMTYPE_DATA);
  
  FLASH_Lock(FLASH_MEMTYPE_DATA);  
}
void __eeprom_write_32(unsigned short addr_eep,unsigned long data)
{
  FLASH_WaitForLastOperation(FLASH_MEMTYPE_DATA);  
  FLASH_Unlock(FLASH_MEMTYPE_DATA);
  
  FLASH_ProgramByte(addr_eep,   (unsigned char)(data>>24));
  FLASH_WaitForLastOperation(FLASH_MEMTYPE_DATA);
  
  FLASH_ProgramByte(addr_eep+1, (unsigned char)(data>>16));
  FLASH_WaitForLastOperation(FLASH_MEMTYPE_DATA);
  
  FLASH_ProgramByte(addr_eep+2,   (unsigned char)(data>>8));
  FLASH_WaitForLastOperation(FLASH_MEMTYPE_DATA);
  
  FLASH_ProgramByte(addr_eep+3, (unsigned char)(data>>0));
  FLASH_WaitForLastOperation(FLASH_MEMTYPE_DATA);
  
  FLASH_Lock(FLASH_MEMTYPE_DATA);  
}

void __eeprom_write_many(unsigned short addr_eep,unsigned short size,unsigned short dummy,unsigned short addr_ram)
{
  
  FLASH_WaitForLastOperation(FLASH_MEMTYPE_DATA);  
  FLASH_Unlock(FLASH_MEMTYPE_DATA);
  
  for(unsigned short i=0;i<size;i++)
  {
     FLASH_ProgramByte(addr_eep+i,   *((unsigned char *)(addr_ram)+i));
     FLASH_WaitForLastOperation(FLASH_MEMTYPE_DATA);
  }
  
  FLASH_Lock(FLASH_MEMTYPE_DATA);  
}

主程序测试:
volatile __eeprom __no_init char  eep_u8;
volatile __eeprom __no_init short eep_u16;
volatile __eeprom __no_init long  eep_u32;
void main( void )
{
  eep_u8=123;
  eep_u16=12345;
  eep_u32=123456789;
   
  while(1);
}
沙发
seawwh| | 2011-3-24 11:51 | 只看该作者
我目前在使用 STM8L101, 你提供的办法可以用在STM8L101 ?
我试验了一下发现一个错误:
Error[Lc36]: no block or place matches the pattern "zi section .eeprom.noinit in Main.o"

使用特权

评论回复
板凳
CC2530|  楼主 | 2011-3-24 11:55 | 只看该作者
STM8L101 没有EEPROM

使用特权

评论回复
地板
seawwh| | 2011-3-24 12:18 | 只看该作者
我使用的是 STM8L101F3P6 ,Flash应该是8K,根据手册应该有EEPROM,在0x9800
看下面的表述(RM0013),其中有些矛盾:TSSOP20 4.4 x 6.4封装的STM8L101F3P6 到底有没有EEPROM ?

EEPROM.jpg (88.96 KB )

EEPROM.jpg

使用特权

评论回复
5
gegegegeda| | 2013-2-14 15:22 | 只看该作者
马克,以后用

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

0

主题

262

帖子

1

粉丝