AnsweredAssumed Answered

QD4 writing flash

Question asked by Saulius Jacenas on Oct 11, 2007
Latest reply on Feb 18, 2010 by Celso Barbante
Hello,

I want to write a byte into non-volatile memory as a calibration constant. As I understood I need a hole flash page for that (safty reasons dicussed in other threads). So I wrote small procedure. And it does not work...

first I reserve that page in the flash:
Code:
unsigned char FLASH_MAS[512] @0xF800;    // rezervuojam page'a flasho rashymui

 
unsigned char FLASH_MAS[512] @0xF800;    // rezervuojam page'a flasho rashymui

write procedure:
Code:
void WriteToFlash(byte data) {  byte z=0;  FCDIV = 39;      // set flash clock , my bus is 8 MHz so 39   for (i=0;i<50;i++);  // wait a bit, just in case    if (!FSTAT_FACCERR) {    FLASH_MAS[0] = data;     // set flash page adress of interest    FCMD = 0x40;            FSTAT_FCBEF=1;       // erase it  if (FSTAT_FPVIOL || FSTAT_FACCERR); // error  else while (!FSTAT_FCCF); // ok, wait for completion  }   StartTX(0x07);  while(SensorState==sTX);   if (!FSTAT_FACCERR) {    FLASH_MAS[0] = data; // put my data to cerain address    FCMD = 0x20;    FSTAT_FCBEF=1;      // write that data  if (FSTAT_FPVIOL || FSTAT_FACCERR); // error  else while (!FSTAT_FCCF); // ok, wait for write completion  }}

 
where is my mistake?

Saulius

Outcomes