|
|
View previous topic :: View next topic |
Author |
Message |
SeeCwriter
Joined: 18 Nov 2013 Posts: 160
|
EEPROM data doesn't persist through power cycle |
Posted: Tue Mar 03, 2015 11:41 am |
|
|
Using a 18F8722 with v5.042 IDE. I can write and read the data eeprom and the data is correct until I power cycle. If I just reset the CPU, the data is also correct. But a power cycle or loading new firmware causes all eeprom reads to return 0xFF.
Is there something I'm doing wrong?
Code: |
#device *=16 ADC=10 ICD=TRUE WRITE_EEPROM=NOINT
#FUSES NOCPD
void GetParameter( long adr, int8 *value, int8 numBytes )
{
int8 i;
for ( i=0; i<numBytes_; i++, adr++ ) {
value[i] = read_eeprom(adr);
}
}
void SaveParameter( long adr, int8 *value, int8 numBytes )
{
int8 i;
for ( i=0; i<numBytes_; i++, adr++ ) {
write_eeprom( adr, value[i] );
}
}
|
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Mar 03, 2015 12:10 pm |
|
|
Quote: |
Using a 18F8722 with v5.042 IDE. I can write and read the data eeprom
and the data is correct until I power cycle. If I just reset the CPU, the
data is also correct. But a power cycle or loading new firmware causes all
eeprom reads to return 0xFF.
Is there something I'm doing wrong? |
When your program starts to run, does it go to the write_eeprom()
routine and over-write your eeprom values ?
When you load new firmware, is this done with an ICD or Pickit type
programmer ? If so, there is a tickbox in the options window for those,
called something like "Preserve eeprom on program". You need to
select that tickbox, to prevent the programmer from erasing your eeprom. |
|
|
SeeCwriter
Joined: 18 Nov 2013 Posts: 160
|
|
Posted: Tue Mar 03, 2015 12:30 pm |
|
|
When the program starts it reads the eeprom to initialize some variables. If the values read from eeprom are not valid, then default values are used and they are written to the eeprom.
I'm using the ICD for programming from the IDE. Is the option in the IDE, because I can't find it, or in CCSLoad? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Mar 03, 2015 1:01 pm |
|
|
I use Microchip tools so I'm completely sure, but this screenshot of
CCSload shows tickboxes on the right, for Program Memory, Data EE
and Config bits. Presumably, if the box is ticked, it will program that
area of the PIC.
http://www.ccsinfo.com/images/content/ccsload.png |
|
|
gpsmikey
Joined: 16 Nov 2010 Posts: 588 Location: Kirkland, WA
|
|
Posted: Tue Mar 03, 2015 1:42 pm |
|
|
You indicate that "If the values read from eeprom are not valid, then default values are used and they are written to the eeprom. ", are you sure it is not thinking they are always invalid when you power cycle? Try disabling the "overwrite if not valid" portion of your code and see what is there. How are you determining if the data in eeprom is valid? Checksum or ??
mikey _________________ mikey
-- you can't have too many gadgets or too much disk space !
old engineering saying: 1+1 = 3 for sufficiently large values of 1 or small values of 3 |
|
|
SeeCwriter
Joined: 18 Nov 2013 Posts: 160
|
|
Posted: Tue Mar 03, 2015 3:28 pm |
|
|
The following code is run one time during power-up initialization. I can break at the 'if' statement and view the value retrieved. The value is always 65535 after reloading the firmware. But after the value is initialized in eeprom, I can reset the program and run again, and the value returned is the default value.
Code: |
int16 val;
GetParameter( FE_VOLTAGE_ADR, &val );
if ( val > 1000 ) {
val = 1000;
SaveParameter( FE_VOLTAGE_ADR, val );
}
SetFEOnVoltage( val );
|
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9226 Location: Greensville,Ontario
|
|
Posted: Tue Mar 03, 2015 4:15 pm |
|
|
hmmmmm.....
ICD=TRUE
This _may_ alter the programming parameters ! Those that use the ICD may know for sure, but I'd say 'FALSE' and c what happens.....
..at least you'd eliminate it as a suspect !
Jay |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Mar 03, 2015 9:34 pm |
|
|
It could be a coding problem, or an IDE with debugger usage problem,
or possibly a hardware problem.
It's difficult to know if it's a coding problem because you haven't posted
consistent code.
For example,
1. Both of your Get/Save routines use a pointer to the data:
Quote: | void GetParameter( long adr, int8 *value, int8 numBytes )
void SaveParameter( long adr, int8 *value, int8 numBytes ) |
But then when you call the routines, you give one of them the address
of the variable, which is corrrect. But for other one, you pass the
variable by value, and that's not going to work:
Quote: | GetParameter( FE_VOLTAGE_ADR, &val);
if ( val > 1000 ) {
val = 1000;
SaveParameter( FE_VOLTAGE_ADR, val );
} |
You can say this is a typo, but these little typos make all the difference
between code working and not working.
Here's another typo. In the declaration you use numBytes, but in the
routine you append an underscore '_' on it. It won't compile.
By the way, tacking an underscore on the end is very bad programming
practice. It's too difficult to distinguish variables at a glance.
Quote: | void SaveParameter( long adr, int8 *value, int8 numBytes )
{
int8 i;
for ( i=0; i<numBytes_; i++, adr++ ) {
write_eeprom( adr, value[i] );
}
} |
And here's another typo. You declared your Get/Save routines as having
three parameters, the 3rd one being 'numBytes'. But when you call them
below, the 3rd parameter is missing:
Quote: | GetParameter( FE_VOLTAGE_ADR, &val );
if ( val > 1000 ) {
val = 1000;
SaveParameter( FE_VOLTAGE_ADR, val );
} |
As it is, I don't know if your problem is caused by:
1. A bug in the CCS IDE with respect to mousing over a variable.
Or a misunderstanding of how that works.
Or a mistaken setup in the options for mousing over display of vars.
2. A problem with typos in your code giving unexpected results.
3. You may have burnt out the eeprom by running it in a fast write loop
for several minutes, and not told us this.
4. Or a combination of those, plus some other problem.
Until we get a clean, tested, consistent test program, I don't see how we
can solve the problem.
To an extent, you are re-inventing the wheel. CCS has routines to write
values to eeprom which are larger than a byte. See this driver file.
Quote: | c:\program files\picc\drivers\internal_eeprom.c |
To access those routines, you would place this line after your #fuses,
#use delay(), etc., lines, but above your other routines and above main():
Code: | #include <internal_eeprom.c>
|
CCS has examples of how to call the int16 versions of those routines
in the following programs:
Quote: | c:\program files\picc\drivers\compass.c
c:\program files\picc\drivers\hmc6042.c |
|
|
|
|
|
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
|