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 CCS Technical Support

Writing EE values during powerup

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



Joined: 22 Sep 2003
Posts: 52
Location: UK

View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger

Writing EE values during powerup
PostPosted: Fri Mar 17, 2006 6:47 am     Reply with quote

Hi All,

I have a project that would greatly benefit from having its EE memory configured with values during the power-up sequence. Does anyone have any experience in this that would be kind enough to share it with me? We could do the configuration after programming by running routines that are hard-coded into the device but this just takes up unnecessary RAM!!

Many thanks,

Jason.
Mark



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

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

PostPosted: Fri Mar 17, 2006 7:10 am     Reply with quote

The eeprom can be loaded with values during the programming phase if you use the #ROM directive. There are examples posted here. I like to have my device configure the eeprom on power up. It doesn't use up RAM but does take up some code space. I pick a location in the eeprom and write a special value to it to know that the eeprom has been configured. On power up, check the location and if the special value is not there, then configure the eeprom. If it is there, then no need to configure it. I like this approach because I give a means for the device to reinitialize (default configuration) in which case these values need to be in there anyways.
StuartH



Joined: 19 Aug 2005
Posts: 14
Location: W. Midlands, UK

View user's profile Send private message

PostPosted: Fri Mar 17, 2006 7:13 am     Reply with quote

Do you mean a one-off configuration? That is, you only want to write to the EEPROM once on the first powerup after the device has been programmed, but ignoring the initialization routine at the next and subsequent powerups?

If that's what you want, the following code snippet shows a method of doing this.
Code:

   //Determine if this is the unit's first power cycle by reading the internal EEPROM in the
   //processor at location 0x18. If the value is nonzero, set
   //appropriate defaults for the external and internal EEPROM
   if( read_eeprom( 0x18 ) )
   {
      restart_wdt();
      write_eeprom( 0x18,0 );         //this routine only runs once, ever!
                 // ....set up your defaults here
   }


This works by detecting the default state of the eeprom after programming (0xFF), running the code block if this is the case, and setting the location to zero so it won't run again. There may be a better way of doing this but it has worked for me in several products over the past 10 years...
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