I have a (long and complex) program that saves data to EEPROM. It doesn't work. To test this out I wrote a small program,
This places (compiles) 0 to 9 in EEPROM at address 0 (0xF00000) - this works.
It copies this data into a RAM array in SFRs - this works.
It then writes A to J into EEPROM - this works. I can read the memory and see the contents of the EEPROM.
It then copies the EEPROM into the RAM (SFR) array - this doesn't work.
I also added the temp=readEEPROM(o) as a test.
ALL of data2 and temp contain 'J' which was the last character written.
I know this will be something simple that I've missed but I just can't see it.
Thanks for any and all help.
Mike.
P.S. if anyone wants to see any thing further (EEPROM readout etc.) then just ask.
Edit, the config bits are set to, CONFIG5H
#pragma config CPD = OFF // Data EEPROM Code Protection bit (Data EEPROM not code-protected)
Code:
const uint8_t data[10] __at(0xF00000)={0,1,2,3,4,5,6,7,8,9};
uint8_t data2[10]={0,0,0,0,0,0,0,0,0,0},temp;
void writeEEPROM(uint8_t,uint8_t);
uint8_t readEEPROM(uint8_t);
void main(void) {
for(uint8_t i=0;i<sizeof(data);i++){
data2[i]=readEEPROM(i);
}
for(uint8_t i=0;i<sizeof(data);i++){
writeEEPROM(i,i+'A');
}
for(uint8_t i=0;i<sizeof(data);i++){
data2[i]=readEEPROM(i);
}
temp=readEEPROM(0);
while(1);
}
uint8_t readEEPROM(uint8_t add){
EEADR=add;
EECON1bits.EEPGD=0;
EECON1bits.CFGS=0;
EECON1bits.RD=1;
return(EEDATA);
}
void writeEEPROM(uint8_t add,uint8_t dat){
//interrupts must be disabled.
while(WR); //allow any existing write to complete
EEADR=add;
EEDATA=dat;
EEPGD=0;
CFGS=0;
WREN=1;
EECON2=0x55;
EECON2=0xAA;
WR=1;
WREN=0;
}
It copies this data into a RAM array in SFRs - this works.
It then writes A to J into EEPROM - this works. I can read the memory and see the contents of the EEPROM.
It then copies the EEPROM into the RAM (SFR) array - this doesn't work.
I also added the temp=readEEPROM(o) as a test.
ALL of data2 and temp contain 'J' which was the last character written.
I know this will be something simple that I've missed but I just can't see it.
Thanks for any and all help.
Mike.
P.S. if anyone wants to see any thing further (EEPROM readout etc.) then just ask.
Edit, the config bits are set to, CONFIG5H
#pragma config CPD = OFF // Data EEPROM Code Protection bit (Data EEPROM not code-protected)
Last edited: