AnsweredAssumed Answered

HCS12 Flash Access Error

Question asked by sebasira on Jun 6, 2012
Latest reply on Jun 8, 2012 by kef

Hello everyone!

 

I'm working with HCS12 and CW4.6.

 

The problem I have is that sometimes, when trying to erase FLASH, I get ACCESS ERROR. I look at the datasheet, and none of the 12 statements that can cause the ACCESS ERROR is true (or so I think, I check them twice).

 

the DoOnStack routine is from AN2720

 

I found out that ACCERR flag is set when I try to erase it.

 

tFLASH_ERROR FLASH_eraseSector(word*__far far_address){      word* address;      tFLASH_ERROR error;            error = FLASH_ERR_NONE;                   // Assume no error     FSTAT = 0x30;// [PVIOL, ACCERR] clear flags          address = (word*)far_address;             // strip PPAGE          if((word)address & 0x0001){       error = FLASH_ERR_ODD_ACCESS;           // Not-Aligned Word     }          if((word)address % FLASH_sectorSize !=0){       error = FLASH_ERR_NOT_START_OF_SECTOR;  // Not sector ini     }          if (error == FLASH_ERR_NONE){       *far_address = 0xFFFF;                 // DUMMY SOTRE        FCMD = ERASE;                           // erase cmd = 0x40                 DoOnStack(far_address);
        }      
        return (error);    }

 

 and when writting 0x30 to FSTAT, ACCERR is set. Why?

 

FLCKDIV = 0xC9 for a 16MHz Xtal

and the far_address = 0x3C8200.

 

It does not always fail. But when it does, is at FSTAT = 0x30

 

What could I be doing wrong?

 

 

Thanks in advance!

Outcomes