I am having a problem reading from the internall EEPROM memory. I am using the learning version of the C18 compiler, ICD2 programmer, and my target is the 18F452 on the PICDEM2+ board.
My problem is that I am unable to read the internal eeprom until after I have unplugged the board from the programmer and removed power from the board. Until I do this, my read function just returns 0. It does not seem to matter whether the data is going into the eeprom from my program or if it is being programmed by the programmer.
This is my code to write to the eeprom:
void eeprom_write (char *buffer) // write string to eeprom
{
unsigned int eeaddress = 0;
char letter;
PIE1bits.TMR1IE = 0; // disable timer1 interrupt
EECON1bits.EEPGD = 0; // address eeprom, not program
EECON1bits.WREN = 1; // Write enable
while(*buffer) //
{
EEADR = eeaddress;
letter = (*buffer);
EEDATA = letter;
EECON2 = 0x55; // I'm told you must do this
EECON2 = 0xAA; // and this too
EECON1bits.WR = 1;
while (EECON1bits.WR)
Nop (); // wait for write to complete
eeaddress++; // point to next storage location
buffer++; // Increment buffer
}
EEADR = eeaddress;
EEDATA = (*buffer);
EECON1bits.WR = 1; // store null character at end of string
PIE1bits.TMR1IE = 1; // enable timer1 interrupt
while (EECON1bits.WR)
Nop (); // wait for write to complete
return;
}
This is the code to read from the eeprom:
void eeprom_read (void) // read string from eeprom
{
unsigned char j = 0;
char read;
do {
EEADR = j;
EECON1bits.EEPGD = 0; // address eeprom, not program
EECON1bits.RD = 1;
read = EEDATA;
incoming[j] = read;
j++; // point to next storage location
}
while(read); // read data from eeprom up through null
return;
}
Has anyone else encountered this? The source file is attached (I think).
Thanks,
-Maarten