Hardware Reference
In-Depth Information
The completion of the command is indicated by the setting of the CCIF flag. An errone-
ous command write sequence will abort and set the appropriate flag. If set, the designer must
clear the ACCERR or PVIOL flags before commencing another command write sequence. By
writing a 0 to the CBEIF flag, the command sequence can be aborted after writing a word to the
EEPROM address space or after writing a command to the ECMD register and before the com-
mand is launched. Writing a 0 to the CBEIF flag in this way will set the ACCERR flag.
The sector-modify command ($60) is a two-step command, which first erases a sector (two
words) of EEPROM and then reprograms one of the words in that sector. The EEPROM sector
that is erased by the command is the sector containing the address of the aligned data write that
starts the valid command sequence. That same address is reprogrammed with the data that is
written. By launching a sector-modify command and then pipelining a program command, it is
possible to completely replace the contents of an EEPROM sector.
Example 14.10
Write a function that erases a sector (4 bytes) of EEPROM. Index register X contains a word-
aligned EEPROM address within the sector to be erased.
Solution: The following assembly function erases the specified EEPROM sector by following
the three-step procedure:
eraseEEsector
movb
#ACCERR 1 PVIOL,ESTAT
; clear error flags
brclr
ESTAT,CBEIF,EERErr
; command buffer not empty, return
std
0,X
; write any data to EEPROM sector
movb
#SectorErase,ECMD
; write sector-erase command
movb
#CBEIF,ESTAT
; launch erase command
brclr
ESTAT,ACCERR+PVIOL,EEROK
; no error?
EERErr
ldab
#1
; error code set to 1
rts
EEROK
brclr
ESTAT,CCIF,EEROK
; wait until command completion
clrb
rts
The C language version of the function is as follows:
int eraseEEsector (int *ptr)
{
ESTAT 5 ACCERR | PVIOL;
// clear error flags
if(!(ESTAT & CBEIF))
return 1;
// command buffer not empty, can't issue new command
*ptr 5 0x00;
// write any data to EEPROM sector location
ECMD 5 SectorErase;
// write sector-erase command
ESTAT 5 CBEIF;
// launch the command
if(ESTAT & (ACCERR | PVIOL))
return 1;
// error occurred
while(!(ESTAT&CCIF));
// wait for command completion
return 0;
// command completed correctly
}
 
Search WWH ::




Custom Search