Hi,
I've some problem to write datas to flash of the SH8. I've made this function to write one byte in to the flash on a specified (empty) address:
unsigned int write_flash(unsigned int indirizzo,byte dato){
while(!FSTAT_FCBEF); //wait if there's another command in progress
if(FSTAT_FACCERR)
FSTAT_FACCERR = 1;
(*((volatile unsigned char *)(indirizzo))) = dato; //write dato in the location defined by indirizzo
FCMD = 0x20; // write byte command
FSTAT_FCBEF = 1; //Send Command
_asm NOP; //Wait 4 cycles
_asm NOP;
_asm NOP;
_asm NOP;
_asm NOP;
while(!FSTAT_FCCF);
return(indirizzo); //return indirizzo to verify if the write location is correct
}
In the main program I want to made a firmware to write once the flash to store some important data like firmware version and some costant, that are useful for the execution of the main alghoritm and then I want to protect this data forever.
My problem is that: when i call multiple times the write flash function, only the firts call work fine.
Example:
address = write_flash(0xEA01,0x10); //this instruction produce the wanted effect
address = write_flash(0xEA02,0x01); // this instruction doesn't work
address = write_flash(0xEA03,0x03); // and also this doesb't work
How can I write multiple locations of the flash in sequence, for instance with a for cycle.
Thak for your help,
Walter