AnsweredAssumed Answered

HCS12XEP100 erase D-FLASH error

Question asked by Jason Cui on May 12, 2016

Hi, all

 

When I tried to erase d-flash of hcs12xep100 with ERASE_D_FLASH_SECTOR(0x12) command, ACCERR error was always emerging. Does anybody can point out what's the problem of my code? Does the eeprom can only be used as partition EEE? Any help would be greatly appreciated! The code is pasted as follows:

 

void DFlash_Init(void)

{

   while(FSTAT_CCIF==0);            //等待正在处理的FLASH操作完成

   FCLKDIV=0x07;                    //外部晶振为8M.FLASH时钟不超过1M,具体参照手册

   FCNFG=0x00;                      //禁止中断

   while(FCLKDIV_FDIVLD==0);        //等待时钟设置成功

}

 

void DFlash_Erase(word ADDR16)

{

  while(FSTAT_CCIF==0);

  if(FSTAT_ACCERR)           //判断并清除标志位;

      FSTAT_ACCERR=1;

  if(FSTAT_FPVIOL)           //判断并清除标志位;

      FSTAT_FPVIOL=1;

 

  FCCOBIX_CCOBIX=0x00;

  FCCOB=0x1210;           //写入擦除命令和高位地址

  FCCOBIX_CCOBIX=0x01;

  FCCOB=ADDR16;           //写入低16位的地址

  FSTAT_CCIF=1;           //启动执行命令

  while(FSTAT_CCIF==0);   //等待执行完成

}

 

void main(void)

{

    DFlash_Init();                  //初始化Flash

    DFlash_Erase(data_Address);     //确保先擦除后写入

 

  for(;;)

  {

  }

}

Outcomes