javi santana

problems erasing EEPROM (9S12NE64)

Discussion created by javi santana on Jan 22, 2007
Latest reply on Jan 27, 2007 by Butcher
i have this code:

const uint8* eeprom_mem_base = (uint8*)0x0800;

volatile uint8 ECLKDIV @(REG_BASE + 0x110);
volatile tFSTAT ESTAT @(REG_BASE + 0x115); /*EEPROM status register */
volatile tFCMD ECMD @(REG_BASE + 0x116); /*EEPROM command buffer */

int main()
{
...
___INITEE = 0x09; /* lock EEPROM block to end at 0x0fff */
...
InitEEPROM();
...
}
//---------------------------------------------

void InitEEPROM(void)
{
const int OscFreq = 25000;
ECLKDIV = ((OscFreq/200/8)-1) + 0x40;
FCLKDIV = ((OscFreq/200/8)-1) + 0x40;
EraseEEPROM (eeprom_mem_base);
}

//---------------------------------------------
uint8 EraseEEPROM(uint16* address)
{
int i;

ESTAT.byte = ACCERR | PVIOL;
FSTAT = ACCERR | PVIOL;

*address = 0;
ECMD.byte = MASS_ERASE; //erase cmd (0x41)
ESTAT.byte = CBEIF; //execute command

for(i = 0; i 10;++i)
{
//nop
}
while( !( ESTAT.byte & 0xC0) ); //wait for CBEIF=CCIF=1 (cmd done)
//INFINITE LOOP

//check error
A = FSTAT & 0x30;
if(A)
{
return 0;
}
return 1;


}

i want clear eeprom to write data before but program never ends EraseEEPROM function. I don't know if i'm setting bad ECLKDIV or if i have forgotten initialize some register.

Outcomes