Jim Pantera

more flash write problemo's

Discussion created by Jim Pantera on Sep 26, 2006
Latest reply on Sep 26, 2006 by David Payne
my CW debug environment dosnt work around this code, what's the bad?
alot of the project code is working but nothing makes sense here.
i see the code work on a byte or two sometimes so maybe close.
thanks!

//segment in main.com
Flash_Erase (0xE001);
for(FixedAddres = 0xE000; FixedAddres0xF000; FixedAddres++) {
Flash_Program(0x99);
}

//the main.com segment calls these two functions
//*********>>> erases the page where of Flash indicated by FlashAddress ***********
void Flash_Erase (unsigned int FlashAddress){
FixedAddres = FlashAddress;
if(FSTAT &0x10) FSTAT |= 0x10; //write a 1 to FACCERR to clear only if error
*(volatile unsigned char *)FixedAddres = 0xFF; //write anything anywhere
FCMD = 0x40; //page erase command type.
FSTAT |= 0x80; //Put FSTAT/FCBEF = launch a new burst command & wait 4 cycles
_asm NOP;
_asm NOP;
_asm NOP;
_asm NOP;

while (!(FSTAT & 0x40)); //else wait for comand to complete
}//************************


//*************>>> write byte of data onto the Flash **************
void Flash_Program(Byte data){
if (FSTAT &0x10) FSTAT |= 0x10; //write a 1 to FACCERR to clear

//write to flash
*(volatile unsigned char *)FixedAddres = (unsigned char)data;
FCMD = 0x20; //set command type.
FSTAT |= 0x80; //Put FCBEF at 1.
_asm NOP; //Wait 4 cycles
_asm NOP;
_asm NOP;
_asm NOP;

while (!(FSTAT & 0x40)); //else wait for comand to complete
}//************************

//this varriable is global and looks like
extern unsigned int FixedAddres;

Outcomes