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

Reading and writing to flash

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







Reading and writing to flash
PostPosted: Mon Jul 09, 2007 1:30 pm     Reply with quote

The help files on reading and writing to flash are as clear as mud so can anyone help explain a few things.

When the helpfile says that the function write_program_memory( address, dataptr, count ); needs a pointer to a byte what it actually means is that it needs to be passed a variable and that the count value needs to relate to the size of the variable. Am I right?

That would explain some of the examples provided where dataptr is clearly not a pointer, it is a variable, and clearly not an int8, byte or char.

So, assuming I'm right about this, does this mean that if I do the following:

Code:

signed int16 SomeVariables[32];
write_programe_memory( 0x1000, SomeVariables, 64);


it will copy all 32 Sint16 values from the array to flash?

And will this copy the values back?

Code:

signed int16 SomeVariables[32];
read_programe_memory( 0x1000, SomeVariables, 64);


-------------

My next question is does this work with arrays of pointers, can I do this:

Code:

signed int16* SomePointers[32];
read_programe_memory( 0x1000, SomePointers, 64);


because I need to save large arrays of variables and pointers to variables so they are preserved during power failure.

(I can't test this all out because I'm working from home this week and I don't have my Pics or programmer here)

Hope someone can help!
grasspuddle



Joined: 15 Jun 2006
Posts: 66

View user's profile Send private message

PostPosted: Mon Jul 09, 2007 1:44 pm     Reply with quote

program memory is the executed code, I believe you want the 'write_eeprom()' and 'read_eeprom()' command

see example ex_intee.c
billy
Guest







Reading and writing to flash
PostPosted: Tue Jul 10, 2007 3:11 am     Reply with quote

Yes, the executed code is stored in flash! On many devices, including the one I'm using (18f4680) the flash is readable and writable by the user code. In my case I have 64kB of flash and my code (almost fully written) uses 16%. this means I can reasonably use 50% (32kB) to store data. Using the EEPROM is not an option as it only has 1024 bytes and I need to store more than 8k of data.

What I wanted was some clarification on how the write_programe_memory(...) functions worked when using different data types like int8, Sint16 and arrays of these variables and arrays of pointers.

About half of the data I want to save to flash are actually pointers so I want to make sure I am saving and retrieving the pointer, not the variable it points to.

Compiler version is 4.041
Billy
Guest







PostPosted: Wed Jul 18, 2007 7:27 am     Reply with quote

Ok, I worked it all out and posted some example code showing how to read and write various types of data and pointers to flash - this is now in the code library section of the forum
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