EEPROM word program problem, only without BDM!!

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

EEPROM word program problem, only without BDM!!

1,474 Views
Bull09
Contributor I

Hi everybody,

I’have a problem when I try to program a word in the EEPROM of my MCU (MC9S12DG128). I develop a code for achieving it following the registers definition explained in the document S12EETS2KV1, from MCU datasheet section 18.

The code that I develop runs perfectly when I debug the application using the BDM (USB Multilink Interface by PE MICRO); But when I unplug the BDM connector and runs the application alone it doesn’t works!!!

I was looking some FAQ’s that are posted in the forum, but neither of them could solve the problem. (Ex: I’m sure that my code writes the register ECLKDIV only once).

The only thing where I suppose that the problem should come is from the mode of the MCU operation. In the MISC register I saw that: when the BDM connector was plugged in the board, the MCU runs in “Special Single Chip mode”. And when the BDM was unplugged the MCU runs in “ Normal Single Chip mode”.

Following I attached the code that I develop for my application

#pragma DATA_SEG EEPROM_DATA

int DATA1;

#pragma DATA_SEG DEFAULT

void EEPROM_INIT (void)

{

    EEPROM_ERROR=0x00;                                  

    if (~ECLKDIV&0x80){

              INITEE=0x21;                                      

              ECLKDIV=0x28;                                      

              ECNFG=0x00;                                        

              ESTAT&=0x30;

     } else EEPROM_ERROR=0x01;

     if (~EPROT&0x88) EEPROM_ERROR=0x02;

}

void EEPROM_ERASE (void){                      

    EEPROM_ERROR=0x00;     

    if (ESTAT&0x30) ESTAT&=0x30;         

    ECMD=0x41;                               

    ESTAT=0x80;                                      

    ECNFG=0x40;                                      

}

void EEPROM_WRITE (int *VAR, int E_DATA){

    EEPROM_ERROR=0x00;                                

    if (ESTAT&0x30) ESTAT&=0x30;

    EDATA=E_DATA;

    EADDR=(int)(VAR);         

    ECMD=0x60;

    ESTAT=0x80;

    ECNFG=0xC0;

}

In the *.PRN file I placed the EEPROM memory as follow:

SEGEMENTS

    EEPROM = NO_INIT 0x2000 TO 0x2800;

END

PLACEMENT

   EEPROM_DATA                  INTO  EEPROM;

END

Everybody could help me to solve the problem??

Thanks in advance for all.

Best Regards,

Lluis Olivet Cos

Labels (1)
0 Kudos
2 Replies

372 Views
kef
Specialist I


Bull09 wrote:

void EEPROM_WRITE (int *VAR, int E_DATA){

    EEPROM_ERROR=0x00;                                

    if (ESTAT&0x30) ESTAT&=0x30;

    EDATA=E_DATA;

    EADDR=(int)(VAR);         

    ECMD=0x60;

    ESTAT=0x80;

    ECNFG=0xC0;

}



Your algorithm isn't right. If you read EDATA and EADDR register description once more again, then you may notice that "In normal modes, all EDATAHI and EDATALO bits read zero and are not writable. In special modes, all EDATAHI and EDATALO bits are readable and writable."
So you shouldn't use EDATA and EADDR registers, but indeed write aligned word directly to EEPROM address space, like docs suggested algorithm suggests. See EETS2K Block User Guide V1.05, Section 4 Functional Description, 4.1.2 Program and Erase. Regards
0 Kudos

372 Views
Bull09
Contributor I
Dear kef,
 
 You are right!!! Apologies my mistake!!! I didn't notice it!!
 
 Thanks a lot for your comment!!! I solve the problem yet.
 
Best regards,
 
Lluis Olivet Cos
0 Kudos