MC9S12DGxxx access some address value in EEPROM from application code in flash area

cancel
Showing results for 
Search instead for 
Did you mean: 

MC9S12DGxxx access some address value in EEPROM from application code in flash area

Jump to solution
86 Views
Contributor I

Hello,

I am wondering if there is some API that I can use in my application code which is flashed into flash area can access the value in some address in EEPROM.

Example:

I use debugger to flash one byte into address 0x401 in EEPROM. Now in my application code which will be flashed into flash area, I would like to have a pointer to access 0x401 and read the value. Is there any function or API?

Best regards,

Zhiqiang Yang

0 Kudos
1 Solution
74 Views
NXP TechSupport
NXP TechSupport

Hi,

Nothing special is needed. Standard pointer access is enough.

I have attached some "historical" examples for diferent device (from memory size point of view) from the same S12 family.

The routines are the same. The difference is only in EEPROM size/placement.

I've also attached an example how to debug EEPROM memory to see changes.

I believe you will understand.

BTW; I have also attached an example for DG256 but in this example I do not use safe functions which ensure the interrupts are disabled while EEPROM is E/W to ensure it is not accessed during this process. The example for DT128 is extended version using extra c,h files for EEPROM processing.

Best regards,

Ladislav

View solution in original post

0 Kudos
2 Replies
75 Views
NXP TechSupport
NXP TechSupport

Hi,

Nothing special is needed. Standard pointer access is enough.

I have attached some "historical" examples for diferent device (from memory size point of view) from the same S12 family.

The routines are the same. The difference is only in EEPROM size/placement.

I've also attached an example how to debug EEPROM memory to see changes.

I believe you will understand.

BTW; I have also attached an example for DG256 but in this example I do not use safe functions which ensure the interrupts are disabled while EEPROM is E/W to ensure it is not accessed during this process. The example for DT128 is extended version using extra c,h files for EEPROM processing.

Best regards,

Ladislav

View solution in original post

0 Kudos
50 Views
Contributor I

Hello @lama 

I solved how to read the eeprom value with normal pointer as you said. But I have some other questions when I read your shared code. I would like to take advantage of one function called EEROM_SectorModify() in the zip SW-DT128-EEPROM-E_W-v1_0-CW47 eeprom.c.

I am new so may I ask where to know  ESTAT_CBEIF, GET_CCR_DIS_I,ESTAT_PVIOL  these kinds of variables? I didn't find definition of these variables. I want to modify values in eeprom in my application code by using 9s12G family.

UBYTE EEPROM_SectorModify(UWORD Addr,ULONG Data)
{
       UBYTE error;

      if (ESTAT_CBEIF == 0) return ERR_BUSY; // Is command buffer full ?
      GET_CCR_DIS_I;
      ESTAT = 0x30; // Clear error flags
      *(volatile UWORD *) Addr = (UWORD)(Data >> 16); // Array address and program data - higher part
      ECMD = 0x60; // Sector modify command
      ESTAT_CBEIF = 1; // Clear flag command buffer empty
      if ((ESTAT_PVIOL == 1)||(ESTAT_ACCERR == 1)) // Is protection violation or access error detected
     {
        RESTORE_CCR;
        return ERR_NOTAVAIL; // If yes then error
      }
      while (ESTAT_CBEIF == 0); // Wait to buffer empty
     error=EEPROM_Word(Addr+2,(UWORD)Data); // Write lower part
     if (error != ERR_OK)
     {  
         RESTORE_CCR;
         return error;
     }
    if (*(volatile UWORD *) Addr != (UWORD)(Data >> 16))
  {
      RESTORE_CCR;
      return ERR_VALUE;
   }
  RESTORE_CCR;
  return ERR_OK;
}

0 Kudos