Kris DelBarba

Flash Writing and Erasing for the MC9S08QG8

Discussion created by Kris DelBarba on Jun 22, 2006
Latest reply on Jul 11, 2006 by ROB LUND
I've read all the previous topics related to this and have not found one to help. Right now I'm trying to write single bytes to Flash and erase pages in flash. I've written a function that seems to work when using single step but if I just let it run the flash isn't written to or erased.

void WriteToFlash(char charinput, int address, short erase)
{
char *write;
int done;

write = (char * )address;

if (1 == FSTAT_FACCERR)
{
FSTAT_FACCERR = 0;
} // end if // clearing Error Field

while (0 == FSTAT_FCBEF)
{
feedCOP();
} // end while // FCBEF Command buffer empty flag 1 means it's empty

*write = charinput; // load into buffer address and char going to write

if (0 == erase) // write
{

FCMD = 0x20; // write one byte
} // end if
else
{
FCMD = 0x40; // erase page the byte would be in

} // end erase else


FSTAT_FCBEF = 1;

asm
{
MUL;
}

if (FSTAT_FACCERR == 1 | FSTAT_FPVIOL == 1)
{
SendMsg("Error!!!!!!");
}

FSTAT_FCBEF = 0;

} // end write to flash

Thanks,

Kdelbarba

Outcomes