How to read the D-Flash

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

How to read the D-Flash

Jump to solution
873 Views
herefent
Contributor I

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.

 

Labels (1)
Tags (2)
0 Kudos
1 Solution
543 Views
herefent
Contributor I

I had solved the problem by myself. Originally, we should set the EPAGE register to determine which D-Flash sector map the local address in 0x0800 that is used as a D-Flash window to access globle address from 0x10000 to 0x101fff.

Here is my code.

void Flash_Init()

{

    FCLKDIV=0x0f;   

    DFPROT=0x80; 

    EPAGE=0x00;      

}

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      = 0x0000;   /* sector address of a D-Flash */

     FSTAT = 0x80;

     while(!FSTAT_CCIF); 

     EnableInterrupts;

    

}

void Flash_Write(unsigned char address,word value){

     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 = 0x0000+address;      //global addr - within an erased sectot

     FCCOBIX = 2;

     FCCOB = value;

     FSTAT = 0x80;

     while(!FSTAT_CCIF);

     EnableInterrupts; 

}

unsigned char Flash_Read(unsigned char address){

     unsigned char *p;

     p=(unsigned char*)(0x0800+address);

     return *p;

}

Because i only have 10 foat-data to store, i just implement a sector of D-Flash which has 256byte.





View solution in original post

0 Kudos
1 Reply
544 Views
herefent
Contributor I

I had solved the problem by myself. Originally, we should set the EPAGE register to determine which D-Flash sector map the local address in 0x0800 that is used as a D-Flash window to access globle address from 0x10000 to 0x101fff.

Here is my code.

void Flash_Init()

{

    FCLKDIV=0x0f;   

    DFPROT=0x80; 

    EPAGE=0x00;      

}

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      = 0x0000;   /* sector address of a D-Flash */

     FSTAT = 0x80;

     while(!FSTAT_CCIF); 

     EnableInterrupts;

    

}

void Flash_Write(unsigned char address,word value){

     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 = 0x0000+address;      //global addr - within an erased sectot

     FCCOBIX = 2;

     FCCOB = value;

     FSTAT = 0x80;

     while(!FSTAT_CCIF);

     EnableInterrupts; 

}

unsigned char Flash_Read(unsigned char address){

     unsigned char *p;

     p=(unsigned char*)(0x0800+address);

     return *p;

}

Because i only have 10 foat-data to store, i just implement a sector of D-Flash which has 256byte.





0 Kudos