CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

EEProm Data appears to be stored incorrectly.

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
JimB



Joined: 25 Aug 2005
Posts: 65
Location: Huntington Beach, CA

View user's profile Send private message

EEProm Data appears to be stored incorrectly.
PostPosted: Wed Mar 29, 2006 10:55 pm     Reply with quote

I am attempting to generate a routine that will load constanst into EEProm for use in setting up a D/A. When I run the code in a loop, I find that the first reads from the EEProm are always FF. After the loop runs again the values are read correctly. If I recompile and run the same code again, I again get FF for the first pass at reading the EEProm. All the printf statements are for me to see what is happening.
Also when a constant is setup as a #define......... how is the declaration for type made. I have not found any examples of this.

Code:

#include <16F877A.h>
#device ICD=TRUE
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#define ref12 0xd000

   main()
   {

      while (1)
      {
      int vrefh, vrefl, vrefhi, vreflo;
     
      vrefh=read_eeprom(0);
      printf("vrefh = %02X\n\r",vrefh);
      vrefl=read_eeprom(1);
      printf("vrefl = %02X\n\r",vrefl);

      vrefhi=make8(ref12,1);
      printf("verfhi = %02X\n\r",vrefhi);
      vreflo=make8(ref12,0);
      printf("verflo = %02X\n\r",vreflo);

      if(vrefh==vrefhi)
      {
      printf("vrefh = %02X\n\r",vrefh);
      }
      else
      {
      write_eeprom(0,vrefhi);
      }
      if (vrefl==vreflo)
      {
      printf("vrefl = %02X\n\r",vrefl);
      }
      else
      {
      write_eeprom(1,vreflo);
      }

      }
   }
Ttelmah
Guest







PostPosted: Thu Mar 30, 2006 3:48 am     Reply with quote

0xFF, is exactly what you should get on the first pass. The EEPROM is _blank_ after programming, unless you deliberately tell the compiler to put values there, and for the EEPROM, 'blank', corresponds to all bits being '1'.
Now, when you are testing the loop, is this in a real chip, or an emulator?. Which compiler version?. You are compiling for ICD. Is this what you are using?.
As a general comment, though it is legitimate 'C', to put the variable declarations inside the function loop, I'd stick to putting them at the start of main. CCS, can have some oddities with such declarations, and nothing is gained from putting them inside the loop (unlike the situation for a processor with a data 'stack').
The #define is fine. The data is automatically a 'long', since it is more than 8bits in size. If you want to force a long declaration, simply append an 'L'.
As another general comment, always 'bracket' numeric declarations. So:
#define ref12 (0xD000L)
This avoids potential problems latter, where if you use such a definition inside a statement that results in arithmetic/logic expressions being carried ot, the 'unbracketed' form, can result in the expression not evaluating as you expect...

What you show, should work, but it is slightly confusing, storing the value MSB first (at the end of the day, why not have byte 0 at index 0, and make it less likely that you will get confused latter from the bytes being swapped...).

Best Wishes
JimB



Joined: 25 Aug 2005
Posts: 65
Location: Huntington Beach, CA

View user's profile Send private message

PostPosted: Thu Mar 30, 2006 11:07 am     Reply with quote

I am running this with a development board, so the real hardware is being used. I am using compiler version 3.232. Shouldn't the "write_eeprom" put data into the EEProm that is preserved after turning off the power or for that fact for any events other than another write_eerpom command? I started viewing the EE information in the debugger window and noted that it is stored after running a few loops through and then stopping. However, just after re-compiling, but before running the code again, I see that the EEPRom has been reset (?) to FF again. It appears to me that the EEProm gets reset every time a compilation occurs. If this is true that means for each new compilation, there always must be code to reload the EEProm, hence the read and check to insure that the correct values are in place.

I assume that when you say "tell the compiler to put values there" you are referring to the write_eeprom command? If not, I am missing something more fundamental.

The order of the address's used is simply because I removed several other stored constants to be brief here. I am still very much a student.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Mar 30, 2006 1:37 pm     Reply with quote

Quote:
It appears to me that the EEProm gets reset every time a compilation occurs.

To preload the EEPROM with data so that after a compilation, you
can see it with the View / EEPROM menu (in MPLAB), use the method
shown in the following thread:
http://www.ccsinfo.com/forum/viewtopic.php?t=19607
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Thu Mar 30, 2006 1:49 pm     Reply with quote

There is also an option to NOT program the eeprom which would prevent the previous data from being erased.
JimB



Joined: 25 Aug 2005
Posts: 65
Location: Huntington Beach, CA

View user's profile Send private message

PostPosted: Thu Mar 30, 2006 2:16 pm     Reply with quote

This is mainly an excercise for the student. It gives me some direct assurance that what I am doing (storing data in the EEProm) is functioning correctly. In the final code the EEProm values stored will not be checked each time the program is run. In fact they will be changed whenever a calibration routine is run. They will be called for use later. If the vaues in this example were to remain in the EEProm as I had expected, then there would be no writing to it. This is to check to see that what was put there previousley is still there, but if incorrect, the values are re-written again.
JimB



Joined: 25 Aug 2005
Posts: 65
Location: Huntington Beach, CA

View user's profile Send private message

Foun the answer
PostPosted: Thu Apr 06, 2006 9:52 am     Reply with quote

I thought I would post this little tidbit since I did not ask the question directly. That was "does the compiler reset the EEProm during compile time". The short answer is yes....at least in my case.
Now I find that there is a setting, in the ICD, that disables this reset feature. However, in my case, I found that the compiler must be running. Then go to the ICD in the Windows start menu, not the selection under the Tools menu. When the ICD window opens, click on the Advance button. Now you will see three choices for handling the EEProm memory. When I selected to do nothing, all was as I desired. Now when data is read to the EEProm, it remains there even after I recompile.
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Thu Apr 06, 2006 12:04 pm     Reply with quote

Yeah, that is what my last post eluded to Very Happy
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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