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

write_program_eeprom question

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



Joined: 01 Apr 2004
Posts: 43
Location: Boston

View user's profile Send private message Visit poster's website

write_program_eeprom question
PostPosted: Tue Aug 31, 2010 9:02 am     Reply with quote

the manual says:

WRITE_PROGRAM_EEPROM - Writes 2 bytes, no erase is needed

Does this mean that the CCS code reads a block, modifies the 2 bytes, and then writes the entire block back?

Or, does is just write the two bytes and I am responsible for having pre-erased the appropriate locations?
_________________
Jon
bkamen



Joined: 07 Jan 2004
Posts: 1615
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Tue Aug 31, 2010 12:27 pm     Reply with quote

You have to follow the rules outlined in the datasheet for erasing blocks.

There is usually a minimum page erase size.

So while you can write the bytes back 2 at a time, you may wipe out 1024 bytes while prepping to write those 2.

That's what you need to keep in mind.

If you're using the Prog FLASH as EEPROM, then you also need to make sure the PIC has enough room to hold 1 page so you can read it all, modify what you want and then write it back, 2 bytes at a time or more.

-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Aug 31, 2010 1:24 pm     Reply with quote

You didn't give your PIC, so I looked at the .LST file for an 18F452.
The write_program_eeprom() doesn't do an erase. It does a read-
modify-write operation on 2 bytes in a 8-byte block in program flash
memory. There is no erase.

But if you look at the .LST file code for write_program_memory(),
you will see the Erase code. It's similar to the ASM example shown
in the 18F452 data sheet. In other words, in a case where an erase
is needed, the compiler puts in the code to do it. You don't have to
worry about it.
dgoldman



Joined: 24 Aug 2010
Posts: 7

View user's profile Send private message

PostPosted: Mon Dec 13, 2010 3:42 pm     Reply with quote

For the 452 with write_program_eeprom(), the erase is handled automatically? Great!

The data sheet shows erase is only automatic when writing FLASH_WRITE_SIZE (64) bytes. This requires write_program_memory() I assume. Compiler to the rescue I guess.

Write_program_eeprom() can write 2 bytes anywhere in program memory without erasing? If I need to write more than 2 bytes, I should use write_program_memory() and stick with FLASH_WRITE_SIZE length to assure efficiency?


So is it generally good practice to then read and checksum to verify the write?
bkamen



Joined: 07 Jan 2004
Posts: 1615
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Mon Dec 13, 2010 9:43 pm     Reply with quote

dgoldman wrote:
For the 452 with write_program_eeprom(), the erase is handled automatically? Great!

The data sheet shows erase is only automatic when writing FLASH_WRITE_SIZE (64) bytes. This requires write_program_memory() I assume. Compiler to the rescue I guess.

Write_program_eeprom() can write 2 bytes anywhere in program memory without erasing? If I need to write more than 2 bytes, I should use write_program_memory() and stick with FLASH_WRITE_SIZE length to assure efficiency?


So is it generally good practice to then read and checksum to verify the write?


Unless you want error correction for long term apps, you probably don't need to read/chksum/write. It's all happening in the PIC.

If you do this over a long time though, remember that the FLASH ages and has a specified number of writes.

As for write_program_memory, remember, you can't just write anywhere in a block any time you like. Those 2 bytes (or a row) has to be erased if the 2 bytes have been written to? How do you keep track of that?

It's proper to read a block in an array, modify the array and then write it back out either as a block or 2bytes at a time.

-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
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