Take the 2-minute tour ×
Electrical Engineering Stack Exchange is a question and answer site for electronics and electrical engineering professionals, students, and enthusiasts. It's 100% free, no registration required.

An easy question, I hope! I'm not finding any definitive answers...

I'm writing drivers for a SST25VF064C flash memory chip. It communicates via SPI.

Like all flash memory (that I know of), it needs to be erased (all bits = 1) before it can be written (bits = 0). For this chip, the smallest area that can be erased is 4kB.

Its memory is divided into 256-byte pages. With one instruction, I can write anywhere from one byte to 256 bytes into a specified page. I don't have to start on a page boundary: the first location to be programmed can be anywhere within a page.

The general rule is to make sure that the page is erased before writing into it. But, can I write into a previously-written page, if I avoid the already-written areas? For example, say that I store data into bytes 0-127. Can I later write another 128 bytes into the same page, if I start at byte 128?

share|improve this question

2 Answers 2

up vote 10 down vote accepted

Yes, after any erase, you can use any number of separate operations to write data (changing bits from 1 to 0) before the next erase operation.

You can even rewrite a previously-written location, as long as you are only clearing more bits. This can be handy for maintaining things like allocation bitmaps.

share|improve this answer
Excellent, Thanks! This was just what I was looking for. –  bitsmack Jul 23 '14 at 22:37
Note that some chips do not like you writing an earlier byte after a later one from looking at various data sheets, however this seems to vary across devices. –  Vality Jul 24 '14 at 9:00
@Vality: Can you provide an example of this? –  Dave Tweed Jul 24 '14 at 11:20
@DaveTweed NXP LPC21xx and LPC23xx MCUs have a checksum byte for every 16 bytes of memory; you must write all 16 bytes at once because the checksum is written in that operation. If you come later and attempt to write zeros in the same "line", the zeros are written, but a new checksum is written over the previous as well; chances are that it has some 1's where the previous had 0's, so the checksum becomes invalid. I don't remember if the MCU permits you to read a line with a bad checksum. Anyway, that would be an example of "vary across devices". –  Guillermo Prandi Jul 26 '14 at 20:22

It is highly likely that the programming software that you are using is already writing the "required" 256 bytes. It "appears" like its is giving you the capability of writing from one to 256 bytes, but I suspect that what it is doing is OR-ing the byte(s) you want with a "mask" of 256 "FF." If this is correct, then you can "safely" write any byte once, without having to erase the whole 4K bytes. If a checksum is written outside of your control, then, most likely, an invalid checksum will be created when you write another byte into a previously written segment. The implications of this, is chip dependent.

If your programming software, does not do the "OR-ing," you can do it yourself. Clear a 256 byte segment, write the byte(s) into the correct position(s), OR with a 256 byte mask of FFs, and write the segment to the desired page.

Whether either method works with any particular chip, can be easily determined by you. Write to the first 128 bytes, write to the second 128 bytes, verify that the first 128 bytes are NOT "messed up"!

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.