View previous topic :: View next topic |
Author |
Message |
schmez
Joined: 14 Jun 2011 Posts: 24 Location: St. Louis
|
Example writing to EEPROM |
Posted: Thu Sep 29, 2011 6:20 am |
|
|
Anyone have an example of how to successfully write a string of characters to eeprom? This snippet does but it seems to trash memory - have to power cycle after doing it.
Any examples or comments on the code below would be appreciated.
void BT_WRITE()
{
output_high(PIN_C2); //Turn on WRITE LED
gets(BTPAIR_ADR); //Get string
if (RS232_ERRORS == 0) //Timeout (10sec) occurs - no string
{
return;} //exit write mode
BTPAIR_ADR[29] = '\0'; //add null to end of string
strncpy (BTPAIR_MEM_STC_BW, BTPAIR_ADR, 24); //copy first 24 characters
for(i = 4; i < 23; i++)
{
write_eeprom(i,BTPAIR_MEM_STC_BW[i]);
}
i++;
*i = '\0'; //add null to end of string
}
return; |
|
|
jeremiah
Joined: 20 Jul 2010 Posts: 1348
|
|
Posted: Thu Sep 29, 2011 7:15 am |
|
|
it's really hard to read your code (use the code tags and indent), so forgive me if I missed this:
I don't see where the loop variable i is declared, but from the way you are using it in the loop, I would guess it is some sort of int.
If that is the case, calling:
Code: |
*i = '\0'; //add null to end of string
|
does nothing to the string, but instead assigns a value of 0 to the memory address 24, which I am guessing is part of the PIC registers. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Sep 29, 2011 1:09 pm |
|
|
Quote: | Anyone have an example of how to successfully write a string of characters to eeprom?
|
This thread shows how to write "Hello World" to external eeprom and
then read it back:
http://www.ccsinfo.com/forum/viewtopic.php?t=35685 |
|
|
|