AnsweredAssumed Answered

How to use S12VR internal eeprom?

Question asked by JT Park on May 18, 2015
Latest reply on Jul 20, 2015 by JT Park

Hello.

 

I used S12VR.

I want to write or read from internal EEPROM of S12VR.

so,

 

////////////////////////////////////////////////////////////////////////////////////////////////////////////

static volatile word data[] ={0x1234,0x4567,0x6789,0x9123};
word eeprom_address = 0x400 ;

static byte start_flash_command_and_wait[]={
    /*Clear FSTAT*/
    /*BSET FSTAT 0x80*/
    0x1C, 0x01, 0x06, 0x80,
    /*Wait for command to end*/
    /*BRCLR FSTAT 0x80*/
    0x1F, 0x01, 0x06, 0x80, -5,
    /*Return*/
    0x3D
};

 

void main()

{

 

   CPMUOSC_OSCE = 0;    /*Using internal OSC. FREF = 1MHz*/

   CPMUSYNR_SYNDIV = 0x18;  /*FVCO = 50MHz = 2*FREF/(0x18+0x01)*/

   CPMUSYNR_VCOFRQ = 0x01; /*48MHz < fVCO<= 50MHz*/

   while (!CPMUFLG_LOCK){}  /* Wait for PLL to lock */

   CPMUCLKS_PLLSEL = 1;  /* select the PLLCLK/2 as the bus clock */       

   CPMUPOSTDIV = 0;    /*FPLL = FVCO/(POSTDIV + 1) = 50MHz*/

                   /*FBUS = 25MHz*/

   ECLKCTL_NECLK = 0; /*Mirror Bus clock to a PIN...Only use it for reference purposes not to clock another device*/

 

 

    FCCOBIX = 0 ;

    FCCOB = 0x1100 ;

    FCCOBIX = 1 ;

    FCCOB = eeprom_address ;

    eeprom_address+= 8;

    while (!FSTAT_CCIF);

    FSTAT=0x30;

    for (FCCOBIX=2; (FCCOBIX<(4+2)); FCCOBIX++){

     FCCOB = data[FCCOBIX-2];

    }

    FCCOBIX--;

    asm(PSHC);

    asm(SEI);

    asm BSR  start_flash_command_and_wait;

    asm(PULC);   

    for(;;)

 

 

 

 

 

 

 

 

 

 

 

     _FEED_COP(); /* feeds the dog */

     }

 

}

////////////////////////////////////////////////////////////////////////////////////////////////////////////

 

what is wrong?

Do you have an exam code to read or write internal eeprom?

help me plz.

thanks.

Outcomes