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