AnsweredAssumed Answered

How to read the D-Flash

Question asked by He refent on May 18, 2013
Latest reply on May 20, 2013 by He refent

I am programming  the function of writing and reading data from D-Flash of the mc9s12xs128maa.

It seem that i can erase and write the sector because the FSTAT is 0x80 after i called Flash_Erase() and Flash_Write(),but i don't konw how to read the data from D-Flash.Could someone help me?

Here is my code:

 

void Flash_Init()

{

    FCLKDIV=0x0f;   

    DFPROT=0x80;        

}


void Flash_Erase() {

     DisableInterrupts;

    if ((FSTAT & 0x30) != 0) {

         FSTAT |= 0x30;         // clear ACCERR or FPVIOL if set

    }

     FCCOBIX   = 0x00;       /* index 0 */

     FCCOBHI   = 0x12;       /* D-Flash Erase command */

     FCCOBLO   = 0x10;       /* Global address value i.e. G-Page value */

     FCCOBIX   = 0x01;       /* index 1 */

     FCCOB      = 0x0f00;   /* sector address of a D-Flash */

     FSTAT = 0x80;

     while(!FSTAT_CCIF); 

     EnableInterrupts;

    

}

void Flash_Write(unsigned char address){

     DisableInterrupts;

     while(FSTAT_CCIF==0) ;

     if ((FSTAT & 0x30) != 0) {

         FSTAT |= 0x30;         // clear ACCERR or FPVIOL if set

      }

     FCCOBIX = 0;

     FCCOBHI = 0x11;     // prog D-flash

     FCCOBLO = 0x10;     // global addr

     FCCOBIX = 1;

     FCCOB = 0x0f00;      //global addr - within an erased sectot

     FCCOBIX = 2;

     FCCOB = 0xabab;

     FCCOBIX = 3;

     FCCOB = 0xabab;

     FSTAT = 0x80;

     while(!FSTAT_CCIF);

     EnableInterrupts; 

 

}

 

word Flash_Read(unsigned char address){

     word *p;

     p=(word*)(0x100f00);

     return *p;

}  


Flash_Init();

Flash_Erase();

Flash_Write(0);

Flash_Read(0);

called in main.

 

thinks.

 

Outcomes