View previous topic :: View next topic |
Author |
Message |
jventerprises
Joined: 01 Apr 2004 Posts: 43 Location: Boston
|
write_program_eeprom question |
Posted: Tue Aug 31, 2010 9:02 am |
|
|
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
|
|
Posted: Tue Aug 31, 2010 12:27 pm |
|
|
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
|
|
Posted: Tue Aug 31, 2010 1:24 pm |
|
|
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
|
|
Posted: Mon Dec 13, 2010 3:42 pm |
|
|
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
|
|
Posted: Mon Dec 13, 2010 9:43 pm |
|
|
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 |
|
|
|