View previous topic :: View next topic |
Author |
Message |
jamesjl
Joined: 22 Sep 2003 Posts: 52 Location: UK
|
Writing EE values during powerup |
Posted: Fri Mar 17, 2006 6:47 am |
|
|
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
|
|
Posted: Fri Mar 17, 2006 7:10 am |
|
|
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
|
|
Posted: Fri Mar 17, 2006 7:13 am |
|
|
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... |
|
|
|