S12XDP512 - EEPROM Programming

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

S12XDP512 - EEPROM Programming

2,070 Views
alefsaeusb
Contributor I
Hi I make a program that change the content of the EEPROM in the HCS12XDP512 MCU, but works only when I use the MCU with BDM, when the MCU is running alone the EEPROM programming doesn't work
can someone help me with that please?


--
Alban Edit: Please always include FSL Part Number in Message Subject line.



Message Edited by Alban on 2007-09-08 07:26 PM
Labels (1)
0 Kudos
3 Replies

372 Views
ThomasG
Contributor I
I have a problem in trying to reprogram the EEPROM.
 
I am using the MC9S12XDT256CAG and trying to test code to erase and write to the EEPROM space.
 
I set up the linker file as shown below:
 
EEPROM_13_GLOBAL = READ_ONLY 0x13F000'G TO 0x13F3FF'G; // 1 KByte global space covering PAGES F8 - FB
      //EEPROM_FC     = READ_ONLY   0xFC0800 TO 0xFC0BFF;
      EEPROM_FD     = READ_ONLY   0xFD0800 TO 0xFD0BFF;
      EEPROM_FE     = READ_ONLY   0xFE0800 TO 0xFE0BFF;
 
I made the page I wanted to access a global address so I could the far pointer type.
 
I then have a function to write to the EEPROM that is as follows:
 
tS08 Write_Word_EEPROM(unsigned int *far wr_address, tU16 wr_data)
{
    tS08 access_status = 0;
    Eeprom.estat.byte = (PVIOL | ACCERR); // Clear any errors
    *(wr_address) = wr_data;
    Eeprom.ecmd.byte = PROGRAM_WORD;
    Eeprom.estat.bit.cbeif = 1;
    while (Eeprom.estat.bit.cbeif == 0)
    {   // Wait for command buffer empty interrupt flag to be set to 1.
    };
    while (Eeprom.estat.bit.ccif == 0)
    {   // Wait for command complete interrupt flag to be set indicating
    };  //  that the command operation has completed.
    if (Eeprom.estat.bit.accerr || Eeprom.estat.bit.pviol)
    {
        if (Eeprom.estat.bit.accerr)
        {
            access_status = EEPROM_ACCESS_ERROR;
        }
        else
        {
            access_status = EEPROM_PROTECT_ERROR;
        }
    }
    else
    {
        access_status = EEPROM_SUCCESS;
    }
    return (access_status);
}
 
and make the call to this function as shown below:
 
EEPROM_status = Write_Word_EEPROM((unsigned int *far)0x13F000, 0xAAAA);
 
when I do this write, the memory locations at 0x13F000 remain 0xFFFF instead of changing to 0xAAAA.
 
Is this because I am using the global pointer instead of setting the pointers up to use the EPAGE register.  If I need to do it using the EPAGE register, how do I set the pointer up for that?  If this is not the case, if you see any mistakes or reasons why this code does not work, I would appreciate it.
 
Also, I noticed the EEPROM address register only stores 11 bits.  Is that because each page is only 1Kbyte?
 
Thank you for the help.
 
-Thomas
0 Kudos

372 Views
kef
Specialist I
Thomas,
 
1) make sure you set ECLKDIV register up before EEPROM write call.
2) make sure debugger doesn't full you caching EEPROM contents. Maybe try to read EEPROM locations back after programming
 
 
Your code looks quite OK and should work. I have just two questions about the code.
 
1)    Eeprom.estat.byte = (PVIOL | ACCERR); // Clear any errors
 
I don't know what tool suite you are using. Looks like CodeWarrior, but CW headers have different defines for EEPROM bits and registers.
My question: It looks like you are using bitfields a lot and I'm not sure if PVIOL is bitmask =0x32, that would be OK. It would be wrong if PVIOL would be a bit from EESTAT bitfield.
 
2)  Eeprom.estat.bit.cbeif = 1;
It doesn't make you code not working, but you should be aware that this line tries to clear not only cbeif bit, but also pviol and accerr bits. I advice you to use cbeif bitmask here.
  
 
Answering your questions:
 
1. Global addressing can be used to program EEPROM, your code should work.
 
2. You wrote: "Also, I noticed the EEPROM address register only stores 11 bits.  Is that because each page is only 1Kbyte?"
 
No, 11 EEADR bits doesn't relate to EEPROM page size. EEADR is an internal address in the EEPROM module. It seems it's word address, not byte address. 2^11 = 2kWords. Try to latch global addresses 0x13FFFE, 0x13FFFC, 0x13FFFA and you should see 0x7FF, 0x7FE and 0x7FD resoectively in the EEADR.
 
Regards
0 Kudos

372 Views
kef
Specialist I
Scroll down and find there Search Board button and edit box. Enter "EEPROM BDM" or something like that. Results are useful, for example:
 
 
 
0 Kudos