AnsweredAssumed Answered

Problem on manipulation data on EEPROM without BDM attached.

Question asked by Gustavo Pimentel on May 20, 2009
Latest reply on Mar 31, 2010 by kef

Hi,

 

i'm developing a program that needs saving some data on EEPROM. With BDM attached i don't have any problems saving data on EEPROM (erasing sectors and writing sectors), but when i remove the BDM i can't save nothing on EEPROM. I have checked the register _EPROT.Byte using BDM and not using, this register has the same data on both cases.

 

I have a 4MHz Crystal and i'm setting PLL to reach 40MHz of Bus Clock. Maybe there is something wrong on my code? I put bellow my functions

 

 /* main.c */

init_clock();                                                  /* Set clock @ 40Mhz */

if(ECLKDIV_EDIVLD==0){ ECLKDIV_EDIV=0x14;}  /* If clock not defined, define now */
EPAGE=0xFC;                                                /* Define EEPROM Page */

 

 /* eeprom.c */

 

void PROGRAM_SECTOR_EEPROM(UINT16 Offset, UINT8* pEEPROMAddress)
{
  UINT8   i=0;
  UINT8*  pPointer=pEEPROMAddress;
 

  if(ECLKDIV_EDIVLD==0){ ECLKDIV_EDIV=0x14;}  /* If clock not defined, define now */
  DisableInterrupts;                          /* Disable all interrupts */
  while(ESTAT_CBEIF==0);                      /* Wait for buffer to be empty */
  if(ESTAT_ACCERR==1||ESTAT_PVIOL==1)         /* Clear error flags */
  {
    ESTAT_ACCERR=0;
    ESTAT_PVIOL=0;
  }
  for(i=0; i<EEPROM_SECTOR_WORD_SIZE; i++)
  {
    EDATAHI=*pPointer;
    pPointer++;
    EDATALO=*pPointer;
    pPointer++;
    EADDRHI=(UINT8)(((Offset+i) & 0xFF00)>>8);
    EADDRLO=(UINT8)(((Offset+i) & 0x00FF)>>0);
    ECMD=0x20;                                /* Run Program Command */
    ESTAT_CBEIF=1;                            /* Run command */
    while(ESTAT_CBEIF==0);                    /* Wait for buffer to be empty */
  }
  while(ESTAT_CCIF==0);                       /* Wait for command to completed */ 
  EnableInterrupts;                           /* Enable all interrupts */
}

 

void ERASE_SECTOR_EEPROM(UINT16 Offset)
{

  if(ECLKDIV_EDIVLD==0){ ECLKDIV_EDIV=0x14;}  /* If clock not defined, define now */
  DisableInterrupts;                          /* Disable all interrupts */
  while(ESTAT_CBEIF==0);                      /* Wait for buffer to be empty */
  if(ESTAT_ACCERR==1||ESTAT_PVIOL==1)         /* Clear error flags */
  {
    ESTAT_ACCERR=0;
    ESTAT_PVIOL=0;
  }
  EDATAHI=0x00;
  EDATALO=0x00;
  EADDRHI=(UINT8)((Offset & 0xFF00)>>8);
  EADDRLO=(UINT8)((Offset & 0x00FF)>>0);

  ECMD=0x40;                                  /* Run Sector Erase Command */
  ESTAT_CBEIF=1;                              /* Run command */
  while(ESTAT_CCIF==0);                       /* Wait for command to completed */ 
  EnableInterrupts;                           /* Enable all interrupts */
}

 

Can anyone help me?

Outcomes