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

Initial value in eeprom on pic18f65k80

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



Joined: 25 Apr 2007
Posts: 14

View user's profile Send private message

Initial value in eeprom on pic18f65k80
PostPosted: Mon Apr 11, 2016 12:22 pm     Reply with quote

Can anyone help me with this? I need to write an initial value on an eeprom location at the time the program is downloaded to the processor. I've successfully written and read to eeprom but haven't find a way to save a value before the program is executed.
Thanks!
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Mon Apr 11, 2016 1:12 pm     Reply with quote

Hi,

Look in the manual at the #ROM pre-processor directive...
_________________
John

If it's worth doing, it's worth doing in real hardware!
ricperez



Joined: 25 Apr 2007
Posts: 14

View user's profile Send private message

Still not working
PostPosted: Mon Apr 11, 2016 1:50 pm     Reply with quote

Thanks ezflyr.

I searched on the posts and found what you suggested; I coded
Code:
#rom  int8 getenv("EEPROM_ADDRESS") = {0x00, 0x01}
to initialize the first two eeprom locations but after downloading to the processor I receive a

CCSLOAD: Error: Verification Error

I suspected it could be fuses related so I made sure there is no eeprom protection at all
Code:

#FUSES NOWDT                      //Watch Dog Timer
#FUSES INTRC
//#FUSES WDT128                   //Watch Dog Timer uses 1:128 Postscale
//#FUSES NOXINST                  //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
//#FUSES NOPUT                      //Power Up Timer
#FUSES NOCPD
#FUSES NOWRTD
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOMCLR                     //Master Clear pin disabled
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES NOFCMEN                  //Fail-safe clock monitor disabled
#FUSES NOIESO                   //Internal External Switch Over mode disabled
#FUSES PUT                       // Power up timer enabled
#FUSES NOPLLEN
//#FUSES PROTECT                  //Code protected from reads
Additionally, the program runs ok, but the variable always shows 255, so the value is not being written!

Any other suggestions?
ricperez



Joined: 25 Apr 2007
Posts: 14

View user's profile Send private message

CCS Ver. 5.052
PostPosted: Mon Apr 11, 2016 3:19 pm     Reply with quote

I forgot to specify the software version.
gpsmikey



Joined: 16 Nov 2010
Posts: 588
Location: Kirkland, WA

View user's profile Send private message

PostPosted: Mon Apr 11, 2016 3:55 pm     Reply with quote

What I do is have a byte that indicates I have set up the initial values. First time the code runs, it sees they have not been set, programs the initial values, sets the flag they have been programmed so from then, when the code starts it skips the setup. Not exactly what you were asking, but it may accomplish what you want without having to do the eeprom as another step.
_________________
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
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Mon Apr 11, 2016 6:58 pm     Reply with quote

Hi,

Hmmm, that should work as coded. I'd probably try a couple of things to keep moving forward:

1. Hard code the EEPROM address from the datasheet and see if it works.
2. See what address the 'Getenv' directive is returning, and compare it to the datasheet.
3. Contact CCS support and see what they say!
_________________
John

If it's worth doing, it's worth doing in real hardware!
ricperez



Joined: 25 Apr 2007
Posts: 14

View user's profile Send private message

I keep trying
PostPosted: Mon Apr 11, 2016 10:00 pm     Reply with quote

Thanks for your input gpsmikey. I've tried that and it worked however it has the inconvenience that everytime the system gets powered down it executes the setting part upon restarting and the value on eeprom which the user had set for, gets overwritten with the initial value.

I'll go after ezflyer's new suggestion (thanks for it ezflyer!) and see what Getenv returns trying to understand what's going on. I may eventually report to CCS since this doesn't seem to be a normal behaviour.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

Re: I keep trying
PostPosted: Mon Apr 11, 2016 10:39 pm     Reply with quote

ricperez wrote:
I've tried that and it worked however it has the inconvenience that everytime the system gets powered down it executes the setting part upon restarting and the value on eeprom which the user had set for, gets overwritten with the initial value.

The eeprom location only gets written once, on the first power-up.
See the sample code in this post:
http://www.ccsinfo.com/forum/viewtopic.php?t=41564&start=6
gpsmikey



Joined: 16 Nov 2010
Posts: 588
Location: Kirkland, WA

View user's profile Send private message

Re: I keep trying
PostPosted: Mon Apr 11, 2016 10:44 pm     Reply with quote

ricperez wrote:
Thanks for your input gpsmikey. I've tried that and it worked however it has the inconvenience that everytime the system gets powered down it executes the setting part upon restarting and the value on eeprom which the user had set for, gets overwritten with the initial value.

I'll go after ezflyer's new suggestion (thanks for it ezflyer!) and see what Getenv returns trying to understand what's going on. I may eventually report to CCS since this doesn't seem to be a normal behaviour.


I guess I wasn't clear about my flag - the flag is a byte I set in the eeprom along with the other data. Now when it powers up, it sees it was configured so does not go back to the defaults (if anything got changed by a user for example).
_________________
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
RF_Developer



Joined: 07 Feb 2011
Posts: 839

View user's profile Send private message

Re: Still not working
PostPosted: Tue Apr 12, 2016 1:31 am     Reply with quote

ricperez wrote:

I searched on the posts and found what you suggested; I coded
Code:
#rom  int8 getenv("EEPROM_ADDRESS") = {0x00, 0x01}
to initialize the first two eeprom locations but after downloading to the processor I receive a

CCSLOAD: Error: Verification Error

Additionally, the program runs ok, but the variable always shows 255, so the value is not being written!

Any other suggestions?


I use other members of this PIC family including the 46k80 and 66k80. I also get EEPROM write/verification problems when I use the Load-N-Go programmer. Basically I can't use the Load-N-Go with these chips if the code has eeprom contents - the eeprom is left unprogrammed. I have to use an ICD-3 instead.

This seems to be a problem in CCSLOAD and/or the programming hardware, not the CCS compiler and can't be fixed in user code. I have told CCS about this several times but so far it's not been fixed :-(
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

PostPosted: Tue Apr 12, 2016 8:50 am     Reply with quote

if this is a one off project, maybe its just simpler to write a small program that writes a variable to your desired eeprom location and the re-program with the code that actually uses that value.

then come back later and learn how to do this properly.

.... its not elegant, and there are definitely ways of doing this at program time, but hey... what ever works.

G.
_________________
CCS PCM 5.078 & CCS PCH 5.093
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