EmbeddedRelated.com
Forums

How to use the EEPROM on MC9S12XDP512?

Started by jeasey February 15, 2009
Hi,Everyone,

NOW,I use XDP512.

I can not use the Internal EEPROM of XDP512 after serveral EEPROM
wrting,erasing and reading test. 

Could anyone give me how to initialize the Internal EEPROM .

It is best if procedure,i can learn it.

Thinks!!


jeasey wrote:
>I can not use the Internal EEPROM of XDP512 after serveral EEPROM >wrting,erasing and reading test. > >Could anyone give me how to initialize the Internal EEPROM .
Have you followed the flow diagram in the datasheet? In particular, have you correctly configured the EEPROM clock register (ECLKDIV). If not, all programming attempts will fail. Andy

jeasey wrote:
> Hi,Everyone, > > NOW,I use XDP512. > > I can not use the Internal EEPROM of XDP512 after serveral EEPROM > wrting,erasing and reading test.
EEPROM works just fine.
> Could anyone give me how to initialize the Internal EEPROM . > It is best if procedure,i can learn it.
RTFM. Check the errata also; there are some special cases with EEPROM. Vladimir Vassilevsky DSP and Mixed Signal Design Consultant http://www.abvolt.com
>Hi,Everyone, > >NOW,I use XDP512. > >I can not use the Internal EEPROM of XDP512 after serveral EEPROM >wrting,erasing and reading test. > >Could anyone give me how to initialize the Internal EEPROM . > >It is best if procedure,i can learn it. > >Thinks!!
The datasheet should get you 95% there procedurally. Also check Freescales site. There's often tutorials on how to do this type of thing.
Hi,Thanks Everyone!
The test code is as follows:

#include <hidef.h>      /* common defines and macros */
#include <mc9s12xdp512.h>     /* derivative information */
#pragma LINK_INFO DERIVATIVE "mc9s12xdp512"

void eeprom_program_cmd(int eeprom_addi, unsigned char *p)
{
  ECLKDIV = 0x15; //16Mhz osc

  DisableInterrupts;
  
  while((ESTAT&0x80)==0x00);
  
  //if(((ESTAT&0x20)==0x20)||(ESTAT&0x10==0x10)) 
    ESTAT=0x30;
  
  EADDRHI=(unsigned char)(eeprom_addi>>8);
  EADDRLO=(unsigned char)eeprom_addi;  
  EDATAHI=*p++;
  EDATALO=*p++;
                  
  ECMD=0x20; //; initiate PROGRAM COMMAND
  ESTAT=0x80; //; begin command
  
  while((ESTAT&0x80)==0x00);

  while((ESTAT&0x40)==0x00); // wait for command to complete

  EnableInterrupts;
}
void eeprom_erase_cmd(int eeprom_addi)
{
  int i=0;

  DisableInterrupts;

  ECLKDIV = 0x15; //4Mhz osc;2M bus clock

  while(ESTAT_CBEIF==0);
  
  if(ESTAT_ACCERR==1||ESTAT_PVIOL==1)
  {
    ESTAT_ACCERR=0;
    ESTAT_PVIOL=0;
  }
  
  EDATAHI=0x0;
  EDATALO=0x0;
  
  EADDRHI=(unsigned char)(eeprom_addi>>8);
  EADDRLO=(unsigned char)eeprom_addi;   
    
  ECMD=0x41; //; all ERASE COMMAND
  
  ESTAT=0x80; //ESTAT_CBEIF=1;// begin command
  
  while(ESTAT_CCIF==1); // wait for command to complete

  EnableInterrupts;
}  

void eeprom_read_cmd(int eeprom_addi, unsigned char *p)
{
  ECLKDIV = 0x15;
  
  DisableInterrupts;

  EADDRHI=(unsigned char)(eeprom_addi>>8);
  EADDRLO=(unsigned char)eeprom_addi;  
    
  *p++=EDATAHI;
  *p++=EDATALO;
  
  EnableInterrupts;
} 

void main(void) 
{
  unsigned char buf1[4]={0x01,0x02,0x03,0x04};
  unsigned char buf2[4]={0};
  /* put your own code here */
  EnableInterrupts;
  
  CLKSEL=0x00;
  
  eeprom_erase_cmd(0x800);
  eeprom_read_cmd(0x800,buf2);
  eeprom_program_cmd(0x800,buf1);
  eeprom_read_cmd(0x800,buf2);
  eeprom_erase_cmd(0x800);
  eeprom_read_cmd(0x800,buf2);
  
  for(;;) 
  {}
  /* please make sure that you never leave this function */
}

There are some questions about this code.I don't know how to solve the
problem.Could you please tell me how to do?
1.The ESTAT register can only be read,and can not be written.
2.if oscillator clock is 4M,the default value of the bus clock is 2M.
Right?
Thanks a lot.Any reply is appreciated!I am looking forward to your reply.