Drew Rainwater

MC9S12A32 EEPROM Program "Attempts" Don't Persist Past Power-Down

Discussion created by Drew Rainwater on Mar 13, 2010
Latest reply on Mar 15, 2010 by kef

Hello all,

 

I'm attempting to program an EEPROM word in the MC9S12A32.  If I erase the sector that the word is in, then program the word, and check it immediately, I am able to read back the value correctly.

 

However, if I then power-down and simply try to read back the value, it no longer matches.  Instead, it's back to $FFFF.

 

Here is some pertinent information:

Oscillator = 4MHz

ECLKDIV = $18  (correctly reads $98 after $18 is written)

INITEE = $21 (to move 2K worth of EEPROM to $2000 - $27FF)

ECNFG = default reset value

 

Here are some snippets of code:

 

        LDX   #CALDONE
        JSR   ERASEE
        LDAA  #$66     
        JSR   PROGEE

         LDD  CALDONE    (D contains $6600 after PROGEE, but not after power-down)

 

---

ERASEE

        BSET EPROT, $80                ;DISABLE EEPROM PROTECTION
        MOVB #$30, ESTAT               ;CLEAR ERROR FLAGS
       
ECHECKCBEIF
        BRCLR ESTAT, $80, ECHECKCBEIF  ;WAIT FOR BUFFERS TO BE EMPTY
        STD 0, X                       ;WRITE ANY DATA TO EEPROM FOR ERASE
        MOVB #$40, ECMD                ;PUT ERASE COMMAND IN COMMAND REG
        MOVB #$80, ESTAT               ;SET CBEIF TO LAUNCH COMMAND

        BRSET ESTAT, #$30, ERASEE      ;COMMAND FAILED IF EITHER BIT IS SET
ECHECKCCIF       
        BRCLR ESTAT, #$40, ECHECKCCIF  ;WAIT FOR COMMAND TO FINISH
       
        BCLR EPROT, $80                ;ENABLE EEPROM PROTECTION

       RTS

 

---

PROGEE

        BSET EPROT, $80                ;DISABLE EEPROM PROTECTION
        MOVB #$30, ESTAT               ;CLEAR ERROR FLAGS
       
PCHECKCBEIF
        BRCLR ESTAT, $80, PCHECKCBEIF  ;WAIT FOR BUFFERS TO BE EMPTY
        LDAB #$00                      ;WRITE '00' AS 2ND BYTE OF WORD
        STD 0, X                       ;WRITE WORD TO EEPROM
        MOVB #$20, ECMD                ;PUT PROGRAM COMMAND IN COMMAND REG
        MOVB #$80, ESTAT               ;SET CBEIF TO LAUNCH COMMAND

        BRSET ESTAT, #$30, PROGEE      ;COMMAND FAILED IF EITHER BIT IS SET
PCHECKCCIF       
        BRCLR ESTAT, #$40, PCHECKCCIF  ;WAIT FOR COMMAND TO FINISH
       
        BCLR EPROT, $80                ;ENABLE EEPROM PROTECTION

       RTS

---

 

Another strange occurrence is that if I try to read back ESTAT, it shows $C1, which is strange because the LSB should be $0 according to the EEPROM User Guide.

 

Can anyone offer some pointers on where to look to see why the data isn't surviving power-down?  I *think* I have the ECLKDIV setup properly, but if it's not, that could lead to the programming failing and maybe I'm reading back a shadowed RAM value before power-down??

 

Thanks in advance.

Drew

Outcomes