Hi, test it,
__DI();
i = flash_erase_sector( 0x10000 );
__EI();
//--------------------------------------------------------------------
unsigned int flash_erase_sector(unsigned int destination) // Sector = 4k
{
unsigned int returnCode=0;
if(FTFL_FSTAT&0b01000000){FTFL_FSTAT&=0b01000000;}
if(FTFL_FSTAT&0b00100000){FTFL_FSTAT&=0b00100000;}
if(FTFL_FSTAT&0b00010000){FTFL_FSTAT&=0b00010000;}
FTFL_FCCOB0 = 0x09;
FTFL_FCCOB1 = (unsigned char)(destination >> 16);
FTFL_FCCOB2 = (unsigned char)((destination >> 8) & 0xFF);
FTFL_FCCOB3 = (unsigned char)(destination & 0xFF);
FTFL_FSTAT = 0x80; // launch command
if(FTFL_FSTAT&0x30){
return(0xff);
}
while(!(FTFL_FSTAT&(1<<7))){}
returnCode = FTFL_FSTAT&0b01110001;
return(returnCode);
}
//---------------------------------------------------------------------