AnsweredAssumed Answered

S12XEP100 EEPROM sometimes gets dirty

Question asked by Alessandro Audero on Jul 16, 2014
Latest reply on Jul 17, 2014 by Alessandro Audero

Dear All,

I've developed a firmware that makes use of the internal S12XEP100 EEEPROM.

Everything works 99% of the time, but sometimes, after a power cycle, the EEEPROM is set to random values.

 

Here there is the init procedure, that is called without interrupt enable, after having set the clock:

 

void E3PROM_setup() {    e3prom_query();    if (erpart == 0xffff || dfpart == 0xffff) {        e3prom_dflash_partition();   }   e3prom_enable();  }

 

Where:

 

e3prom_query is used to retrive parameters from the e3prom

 

void e3prom_query() {   FSTAT = 0x30;   e3prom_wait();   FCCOBIX = 0;   FCCOBHI = 0x15;   FCCOBLO = 0x00;   FSTAT = 0x80;   e3prom_wait();   FCCOBIX = 1;   dfpart = FCCOB;   FCCOBIX = 2;   erpart = FCCOB;   FCCOBIX = 3;   ecount = FCCOB;   FCCOBIX = 4;   deadcnt = FCCOBHI;   rdycnt = FCCOBLO; }

 

e3prom_wait is used to wait for e3prom operations complete

 

void e3prom_wait() {   while((ETAG > 0) || (FSTAT_MGBUSY == 1) || FSTAT_CCIF == 0); }

 

e3prom_dflash_partition is used to partition the dflash

 

void e3prom_dflash_partition() {   FSTAT = 0x30;   e3prom_wait();   FCCOBIX = 0;   FCCOBHI = 0x20;   FCCOBLO = 0x00;   FCCOBIX = 1;   FCCOB = 0x0040;   FCCOBIX = 2;   FCCOB = 0x0004;   FSTAT = 0x80;   e3prom_wait(); }

 

void e3prom_enable() {   FSTAT = 0x30;   e3prom_wait();   FCCOBIX = 0;   FCCOBHI = 0x13;   FCCOBLO = 0x00;   FSTAT = 0x80;   e3prom_wait(); } 

 

And these are the routines to read and write:

 

void E3PROM_set_byte(unsigned long addr, byte val) {   byte * __far ptr = (byte * __far)addr;   *ptr = val; } byte E3PROM_get_byte(unsigned long addr) {   byte * __far ptr = (byte * __far)addr;   return *ptr; } 

 

Unfortunately the problem is happening very rarely and it cannot be reproduced sistematically.

Any hint or suggestion on the code above?

Am I wrong in something?

 

Many thanks in advance,

Ale

Outcomes