problems erasing EEPROM (9S12NE64)

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

problems erasing EEPROM (9S12NE64)

1,682 Views
ethy
Contributor I
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.
Labels (1)
0 Kudos
Reply
2 Replies

575 Views
mjbcswitzerland
Specialist V
Hi

I don't think that the NE64 has any EEPROM - it has FLASH EEPROM, which is erased by writing the MASS_ERASE command to FCMD (address 0x106).
I don't think that there is a register ECMD.
ECMD is a standard register for HC12 with EEPROM (eg. MC9S12DP256 with 4k, ECMD at address 0x116) but there is no mention of this or any EEPROM in the NE64 user's manual and I believe this also to be the case.

Are you confusing FLASH with EEPROM?

Regards

Mark Butcher
www.uTasker.com
0 Kudos
Reply

575 Views
Lundin
Senior Contributor IV
Section 4.1.1 "Writing the ECLKDIV Register".

There you can see that the formula for your case is

INT( (25MHz / 8) * (5 + 0.08us) ) = 15

I don't think the -1 in your code is correct, you should only subtract if the clock cycle + 5 gives you an integer (ie you have a slow-motion oscillator). You end up with value 14 instead of 15.

ECLK = (25MHz / 8) / (15 + 1) = 195kHz, within spec.
ECLK = (25MHz / 8) / (14 + 1) = 208kHz, too fast


Though it seems odd that the EEPROM would be that picky. Perhaps it is, I have no idea. I recognize your error where the program hangs upon EEPROM write though, you get it if you have the wrong prescaler settings.
0 Kudos
Reply