I Can't modify data on eeprom memory

cancel
Showing results for 
Search instead for 
Did you mean: 

I Can't modify data on eeprom memory

2,323 Views
Contributor I
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
Labels (1)
0 Kudos
6 Replies

12 Views
Contributor I
Hi,
Call function eeprom_init() even if EDIVLD bit is not null
 
char modifiy_Sector(unsigned int * adr, unsigned int data)
{
     ESTAT=0x30;//raz  ACCERR et PVIOL
      while(!(ESTAT & 0x80));          // remove this while condition
     *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);
}
 
remove the marked while condition. you can't issue more than one command unless it has been completed.
 
Regards,
Kantha
0 Kudos

12 Views
Contributor I
Hi,

Thank you for your answer, but it seems not to resolve my problem. I analyse
every register needed by the EEPROM and I did'nt find any mistakes.
During my last tests, I've seen that the memory space I was considering as
the eeprom memory was acting as a RAM memory. I mean, when I am executing,
step by step, the command line *eepromAddress = data (as explaining in the
application note), the memory area is updating with the data even if the the
command was not run (with writing the ECMD register and ESTAT_CBIEF bit).
When I shut down the chip power, The memory area is no longer fill with data
I wrote but with random data.
So I thougth it was a mapping memory error.
I want the following mapping:
RAM : 0x1000 to 0x2FFF
EEPROM : 0x800 to 0xFFF
FLASH: 0x4000 et 0x8000

As explaining in the documentation, I configure the mapping registers as
followed:
INITRM = 0x11;
INITEE = 0x09;
INITRG = 0x00;

I saw in the application note you've sent to me, that if a RAM area is at
the same place as the EEPROM area, the sector is acting as a RAM memory. At
reset, the ram memory is placed from 0x0000 to 0x1FFF and is masking the
eeprom memory.What should I do to make the EEPROM visible.


Nicolas DOMBLIDES
0 Kudos

12 Views
Contributor I
Hi,
Remap your RAM to 0x2000, ie INITRM = 0x20;
 
Regards,
Kantha
0 Kudos

12 Views
Contributor I
Hi !

That's it !! I remapped my RAM memory and it's working !!

thank you everybody for your help.

Bibi
0 Kudos

12 Views
Specialist I
bibi,
 
you want to map your DG128 RAM to 1000-2fff. This is impossible since DG128 8K RAM block is "mappable to any 8K boundary". 8K boundary means $0, $2000, $4000, $6000  etc. You can't map DG128's 8K RAM to 1000-2fff. Only 0-1fff, 2000-3fff, etc
 
0 Kudos

12 Views
Contributor I
Hi,
You can't write into EEPROM unless it is empty, means data at that location should be 0xFFFF.
 
Regards,
Kantha
0 Kudos