LUIS JACOBO HERNANDEZ ORTIZ

MC9S12NE Problem to programming part of flash with

Discussion created by LUIS JACOBO HERNANDEZ ORTIZ on Nov 9, 2007
Latest reply on Nov 13, 2007 by Tom Thompson
Hello

I read AN2720 and AN2400 to change the content of memory flash. I made the following
code, i placed flags to know if the program work. The flags noted that the program it's ok.
and that the sector of memory flash it's erased, but when i read the address of memory
the content is the same before that i erased it.

Do you know when there a error?.

The sector is 0x4E00.
The xtal of DEMO9S12NE64 is 25Mhz.
The Software is TCP OPEN and CW is 3.1.

/******call to Function to initiate of memory flash to erase it******/
 Flash_Init();
/****************************************************************/

/*********Function to initiate memory flash to erase it*********/
void Flash_Init(void)
  {
    FCLKDIV = 0x4F;
    FPROT = 0xFF;
    FSTAT = FSTAT | 0x30;
  }
/*************************************************************/

/**********call to Function to erase memory flash ***********/
 erase_sector(0x4E00);
/*************************************************************/

/***************Function to erase memory flash **************/

erase_sector(unsigned int direccion)
  {
    unsigned int* localidad;
    localidad = (unsigned int*)direccion;
        
    if((unsigned int)localidad & 0x0001)
      {
          //flag
      }
    if(((unsigned int)localidad % 0x200) != 0x00)
      {
            //flag
      }
      
    FSTAT = FSTAT | 0x30;  
      
    if(FSTAT_CBEIF==0x01)
      {
        (*localidad)=0xFFFF;  
        FCMD=0x40;
        if((FSTAT_ACCERR==0x01)||(FSTAT_PVIOL==0x01))
          {
               //flag
          }
        while(FSTAT_CCIF != 0x01)
          {
               //flag
          }
      }
    else
      {
             //flag
      }
      
        //flag
  }

Outcomes