|
|
View previous topic :: View next topic |
Author |
Message |
boulder
Joined: 15 Mar 2008 Posts: 53
|
Why Is EEPROM Data Erased? |
Posted: Tue Mar 24, 2009 5:13 pm |
|
|
Hi,
I wrote a very simple code to write 22 byte to EEPROM from address 0 to 21 and read data back successfully.
Code: |
#include <16F689.h>
#include <stdio.h>
#include <stdlib.h>
#use delay(clock=3686400, crystal)
#use rs232(baud=115200, xmit=PIN_B7, rcv=PIN_B5)
#fuses XT, NOWDT, PUT, MCLR, NOPROTECT, NOCPD, NOBROWNOUT, NOIESO, NOFCMEN
unsigned int8 i;
void main()
{
for(i=1; i<=22; i++)
write_eeprom(i-1, i);
for(i=0; i<=21; i++)
putc(read_eeprom(i));
while(1);
}
|
However, if I recompile the code without write_eeprom() and power reset, I read back 0xFF from the same eeprom chip.
Code: |
#include <16F689.h>
#include <stdio.h>
#include <stdlib.h>
#use delay(clock=3686400, crystal)
#use rs232(baud=115200, xmit=PIN_B7, rcv=PIN_B5)
#fuses XT, NOWDT, PUT, MCLR, NOPROTECT, NOCPD, NOBROWNOUT, NOIESO, NOFCMEN
unsigned int8 i;
void main()
{
for(i=0; i<=21; i++)
putc(read_eeprom(i));
while(1);
}
|
Could anybody tell me what I am missing in my code? My compiler is 4.085 and MPLAB IDE is 8.15a.
Thanks. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
boulder
Joined: 15 Mar 2008 Posts: 53
|
|
Posted: Tue Mar 24, 2009 6:07 pm |
|
|
But I am using PICKit2 instead of ICD2. I do not see the option of preserve EEPROM data.
Thanks. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Mar 24, 2009 6:48 pm |
|
|
In MPLAB 8.20a, if you select PicKit2 as the programmer and then go to
the Programmer menu and click on Settings, a dialog box will appear.
In the Settings tab, it has a tickbox for "Preserve Device EEPROM".
If you don't have that option, then I suggest you upgrade MPLAB. |
|
|
boulder
Joined: 15 Mar 2008 Posts: 53
|
|
Posted: Tue Mar 24, 2009 8:59 pm |
|
|
PCM,
Thanks. You are right, the latest version of MPLAB, 8.20a has this option for PicKit2.
I have one more question about read data eeprom. Does it need to add delay between reading each byte data from eeprom? If the answer is yes, what's the minimum delay?
Thanks. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Mar 24, 2009 9:33 pm |
|
|
There is no delay for reading. For writing, the delay is handled by the
CCS compiler in the write_eeprom() function. You don't have to do anything. |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|