eeprom, erase, program - HC9S12DP256

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

eeprom, erase, program - HC9S12DP256

ソリューションへジャンプ
3,386件の閲覧回数
Seitec
Contributor III

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
ラベル(1)
0 件の賞賛
1 解決策
666件の閲覧回数
kef
Specialist I

So what problem do you have with EEPROM? Famous "doesn't work"?

 

I see two bugs in your code.

 

1) ECLKDIV is write once register and this piece of code may lead to damage of EEPROM module:

 

  ECLKDIV_PRDIV8 = 0;
 
  ECLKDIV_PRDIV8 = 1;
  ECLKDIV = 0x4a;                                        //EDIV[5:0]  10   PRDVI8 = 1  EnableInterrupts;

 

 

2) Programming misaligned words or chars is illegal operation:

 

int Writebyte(unsigned char* address, unsigned char data){
  DisableInterrupts;
  ESTAT = ESTAT_ACCERR_MASK | ESTAT_PVIOL_MASK;
  if(ESTAT_CBEIF == 1){
    *address = data;

...

元の投稿で解決策を見る

0 件の賞賛
4 返答(返信)
667件の閲覧回数
kef
Specialist I

So what problem do you have with EEPROM? Famous "doesn't work"?

 

I see two bugs in your code.

 

1) ECLKDIV is write once register and this piece of code may lead to damage of EEPROM module:

 

  ECLKDIV_PRDIV8 = 0;
 
  ECLKDIV_PRDIV8 = 1;
  ECLKDIV = 0x4a;                                        //EDIV[5:0]  10   PRDVI8 = 1  EnableInterrupts;

 

 

2) Programming misaligned words or chars is illegal operation:

 

int Writebyte(unsigned char* address, unsigned char data){
  DisableInterrupts;
  ESTAT = ESTAT_ACCERR_MASK | ESTAT_PVIOL_MASK;
  if(ESTAT_CBEIF == 1){
    *address = data;

...

0 件の賞賛
666件の閲覧回数
Seitec
Contributor III

Thank you very much.

 

Yes, erase don´t work and program too.

 

Is it now right? 

 

1)

 ECLKDIV = value_ediv | PRDIV8;

 

2)

 

int Writebyte(unsigned short* address, unsigned char data){
  DisableInterrupts;
  ESTAT = ESTAT_ACCERR_MASK | ESTAT_PVIOL_MASK;
  if(ESTAT_CBEIF == 1){
    *address = data;

 

Really thank you very much

Message Edited by Seitec on 2009-02-26 09:27 AM
0 件の賞賛
666件の閲覧回数
Seitec
Contributor III
Yes it work :smileyhappy:. thank you very much
0 件の賞賛
666件の閲覧回数
Lundin
Senior Contributor IV
The size of the pointer has no relevance to memory alignment. The HCS12 allows variables in RAM to be stored at odd addresses.

if( ((unsigned short)address % 2) == 0)
{
  *address = data;
}
else
{
  /* error */
}
0 件の賞賛