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

Example writing to EEPROM

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



Joined: 14 Jun 2011
Posts: 24
Location: St. Louis

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

Example writing to EEPROM
PostPosted: Thu Sep 29, 2011 6:20 am     Reply with quote

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: 1321

View user's profile Send private message

PostPosted: Thu Sep 29, 2011 7:15 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Sep 29, 2011 1:09 pm     Reply with quote

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
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