View previous topic :: View next topic |
Author |
Message |
ricperez
Joined: 25 Apr 2007 Posts: 14
|
Initial value in eeprom on pic18f65k80 |
Posted: Mon Apr 11, 2016 12:22 pm |
|
|
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! |
|
![](templates/subSilver/images/spacer.gif) |
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
|
Posted: Mon Apr 11, 2016 1:12 pm |
|
|
Hi,
Look in the manual at the #ROM pre-processor directive... _________________ John
If it's worth doing, it's worth doing in real hardware! |
|
![](templates/subSilver/images/spacer.gif) |
ricperez
Joined: 25 Apr 2007 Posts: 14
|
Still not working |
Posted: Mon Apr 11, 2016 1:50 pm |
|
|
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? |
|
![](templates/subSilver/images/spacer.gif) |
ricperez
Joined: 25 Apr 2007 Posts: 14
|
CCS Ver. 5.052 |
Posted: Mon Apr 11, 2016 3:19 pm |
|
|
I forgot to specify the software version. |
|
![](templates/subSilver/images/spacer.gif) |
gpsmikey
Joined: 16 Nov 2010 Posts: 588 Location: Kirkland, WA
|
|
Posted: Mon Apr 11, 2016 3:55 pm |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
|
Posted: Mon Apr 11, 2016 6:58 pm |
|
|
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! |
|
![](templates/subSilver/images/spacer.gif) |
ricperez
Joined: 25 Apr 2007 Posts: 14
|
I keep trying |
Posted: Mon Apr 11, 2016 10:00 pm |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
Re: I keep trying |
Posted: Mon Apr 11, 2016 10:39 pm |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
gpsmikey
Joined: 16 Nov 2010 Posts: 588 Location: Kirkland, WA
|
Re: I keep trying |
Posted: Mon Apr 11, 2016 10:44 pm |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
RF_Developer
Joined: 07 Feb 2011 Posts: 839
|
Re: Still not working |
Posted: Tue Apr 12, 2016 1:31 am |
|
|
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 :-( |
|
![](templates/subSilver/images/spacer.gif) |
Gabriel
Joined: 03 Aug 2009 Posts: 1067 Location: Panama
|
|
Posted: Tue Apr 12, 2016 8:50 am |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
|