more flash write problemo's

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

more flash write problemo's

2,578 Views
jah
Contributor I
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;
Labels (1)
0 Kudos
4 Replies

317 Views
jah
Contributor I
additonal info:
FCDIV = 0x27 //8Mhz clock from "MC9S08RG60/D Rev. 1.11 06/2005" p50/table4.6
0 Kudos

317 Views
peg
Senior Contributor IV
Hi jah,
These devices only have one array of FLASH.
You must execute from RAM to erase/programme any of it.
See the many other threads on this subject.
Regards
David
 
0 Kudos

317 Views
rocco
Senior Contributor II
Hi, Jah:

Are you running this routine in ram?

If so, how are you moving it to ram?
0 Kudos

317 Views
jah
Contributor I
the routine is running about 0x9000 but in flash
the main.c above are ment to modify flash around 0xE000

thanks for the reply.
0 Kudos