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
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;
}