AnsweredAssumed Answered

eeprom, erase, program - HC9S12DP256

Question asked by Ondrej Machek on Feb 25, 2009
Latest reply on Mar 4, 2009 by Daniel Lundin

Hello I would like ask you.

I have problem with program eeprom.

I am using CodeWarrior, HC9S12DP256 fbus = 8MHz, fosc=16MHz. Are values right?

There is program.

 

 

 EEPROM = READ_ONLY 0x0400 TO 0x0EFF;

 MYPROM = READ_WRITE 0x0F00 TO 0xFEF;

 

 

 

 

int Initi(void){
  DisableInterrupts;
  ECLKDIV_PRDIV8 = 0;
 
  ECLKDIV_PRDIV8 = 1;
  ECLKDIV = 0x4a;                                        //EDIV[5:0]  10   PRDVI8 = 1  EnableInterrupts;
  return 0;
}

int erase_sector(int *ptr){                  /*ptr (unsigned int *far)0x3ff40*/
  DisableInterrupts;
  ESTAT = ESTAT_ACCERR_MASK | ESTAT_PVIOL_MASK;        /* clear error flags */
  if(ESTAT_CBEIF == 1){                      /*buffer full*/
  *ptr = 0x00;
  ECMD = SECTOR_ERASE;                       /*sector erase*/
  ESTAT = ESTAT_CBEIF_MASK;                       /***/
  if(ESTAT & (ESTAT_ACCERR_MASK | ESTAT_PVIOL_MASK)){
    EnableInterrupts;
    return 1;
  }
  while(!(ESTAT & ESTAT_CCIF_MASK));
  EnableInterrupts;
  return 0;                                  /*ok*/
  }else{
    EnableInterrupts;
    return 1;                               /*bad*/
  }
}

int Writebyte(unsigned char* address, unsigned char data){
  DisableInterrupts;
  ESTAT = ESTAT_ACCERR_MASK | ESTAT_PVIOL_MASK;
  if(ESTAT_CBEIF == 1){
    *address = data;
    ECMD = PROG;
    ESTAT = ESTAT_CBEIF_MASK;
    if((ESTAT & (ESTAT_ACCERR_MASK | ESTAT_PVIOL_MASK)) != 0){
      EnableInterrupts;
      return 0;                              /*bad*/
    }
    while(ESTAT_CCIF != 1);
    EnableInterrupts;
    return 1;                                 /*OK*/
  }else{
    EnableInterrupts;
    return 0;                                /*bad*/
  }
}

int Writeword(unsigned int* address, unsigned int data){
  unsigned int a =0;
 a = Writebyte((unsigned char*)address++, (unsigned char)(data>>8));
 a = Writebyte((unsigned char*)address, (unsigned char)data & 0xFF);
  return 1;
 
}

 

Thank you very much

 

Added p/n to subject

Message Edited by NLFSJ on 2009-03-01 12:23 AM

Outcomes