Quote Originally Posted by RussMartin View Post
All flash locations were $0000, and those PICs of course failed the blank check. Then I erased one and read it back in hex. All flash locations are initialized to $3FFF to be "blank", so that's settled.
Never tried it like that...interesting...

$FFFF is a 16-bit value, so you must have assumed a 16-bit word. Since the words in flash are only 14 bits, the math says $3FFF is the largest value possible.
Guess I should've specified. What I really meant was all possible bits set to logic 1.

Do you know this, or are you guessing? I don't see how ORing bits is relevant to the question, but I'm anxious to be informed.
If the erased value of the byte is $ff (assume a byte for the purpose), and you write a $ff, nothing changes. If you write an $f0 next time, the low four bits go to logic 0.
If you try to rewrite $ff, nothing changes, because the only thing that can change a 0 to a 1 is an erasure. Programming changes 1's to 0'.
If you try to rewrite $30, it should change, because you are programming 1's to 0's.
But you're right, I am guessing.
Seems to me that used to be the way people would be able to write patches into UV-EPROM (or PROM for that matter). Changing bytes to all 1's (or 0's) would turn those bytes into NOP's and allow a successive location to be programmed to a JMP to another boot location...something along those lines...

Okay, you've lost me on this one. Please explain: How does disregarding the 2 least significant bits of the address relate to the value stored at that address?
Say you've got an 8 bit address...256 values possible.
If the PIC disregards the bottom 2 bits, it would be addressing 64 possible 'ranges' in 4-byte 'blocks'. Might have something to do with something.

Well, the data sheet seems to disagree. According to it: A read returns 1 word from flash; a write must be done as a block of 4 words; and an erase must be done as a block of 32 words.
Yes, of course, you are correct. I got ahead of myself.
I think in these cases, a read-modify-erase-writeback procedure is needed.
If you want to change one byte, you have to read the whole block that is going to be erased, change the byte you want to change, then write back the block in the 4-byte chunks.

Presumably, one "master" erase of many 32-word blocks would be sufficient for a large number of successive writes.
I think they do that for space reasons. Adding all those extra transistors to 'charge' the cells takes up a lot of space from what I've read about flash memory. Start making the 'blocks' small, and you can't fit as much on a chip. Reading is easy, writing is rough, erasing is hard...comparatively speaking.