I am working on a project using a PIC18F26K20. I need to store several value in EEPROM, but it does not store any data, all I evers get back is 0xff.
Here is the code I am using:
unsigned char ReadEEPROM(unsigned char address){
EECON1=0; //ensure CFGS=0 and EEPGD=0
EEADR = address;
EECON1bits.RD = 1;
return(EEDATA);
}
void WriteEEPROM(unsigned char address,unsigned char data){
char SaveInt;
SaveInt=INTCON; //save interrupt status
EECON1=0; //ensure CFGS=0 and EEPGD=0
EECON1bits.WREN = 1; //enable write to EEPROM
EEADR = address; //setup Address
EEDATA = data; //and data
INTCONbits.GIE=0; //No interrupts
EECON2 = 0x55; //required sequence #1
EECON2 = 0xaa; //#2
EECON1bits.WR = 1; //#3 = actual write
INTCON=SaveInt; //restore interrupts
while(!PIR2bits.EEIF); //wait until finished
EECON1bits.WREN = 0; //disable write to EEPROM
}
Is there something else I need to do to store Data in EEPROM? Or am I doing some thing wrong?
EEIF
so perhaps subsequent writes are getting cancelled early by the lowering of the enable bit the end. PollingWR
directly might be a better bet. \$\endgroup\$