Domblides Nicolas

I Can't modify data on eeprom memory

Discussion created by Domblides Nicolas on Jan 30, 2007
Latest reply on Feb 6, 2007 by DOMBLIDES Nicolas
Hello !
 
I'm using a MC9S12DG128 microcontroler. I would like to modify data writen in eeprom memory.
The chip is used with a 16MHz oscillator.
 
I first initiate the memory mapping :
init_cpu(){
INITEE = 0x09;
INITRM = 0x11;
INITRG = 0x00;
}
 
Before writing data, I'm looking at the EDIVLD bit in the ESTAT register, if null I initiate the EEPROM registers :
void eeprom_init(){
    ECLKDIV=0x4A;
    ECNFG=0x00;//pas it eeprom
}
 
and then I modify the sector :
char modifiy_Sector(unsigned int * adr, unsigned int data){
     ESTAT=0x30;//raz  ACCERR et PVIOL
      while(!(ESTAT & 0x80));
     *adr=data;//fill address with data
      ECMD=0x60;//write command
      ESTAT = 0x80;//activate command
      if((ESTAT&0x30)!=0)
          return(FALSE);
      while(!(ESTAT & 0x40));//wait for end of command
     return(*adr==data);
}
 
The problem is that data are not written in the EEPROM memory ! Did I miss something or Is there any errors in my code ?
 
For more information, I'm using CW compiler, ISystem Debugger. My Controler is used in Normal single chip.
 
Thank you for your help !
 
Bibi

Outcomes