Throughout this post I will refer to this datasheet found on micron.com.
You have asked two questions above which I will cover here:
- Is the address pointer incremented automatically during read/write
- What is the difference between PAGE WRITE and PAGE PROGRAM
First it helps to understand how the memory is arranged internally. The device has 8Mb total flash memory, from page 5 of the datasheet we see:
The memory is organized as 16 sectors, divided into 16 subsectors each
(256 subsectors total). Each sector contains 256 pages and each
subsector contains 16 pages. Each page is 256 bytes wide. The entire
memory can be viewed as consisting of 4096 pages, or 1,048,576 bytes.
(emphasis added by me)
It is important to note that a page, which totals 256 bytes, is the smallest unit we can operate on at once. There are 4096 of these which give our total memory area. We see on the same page that:
The memory can be written or programmed 1 to 256 bytes at a time
You specified in a comment that you want to write 13 bytes at a time. So how would this work?
Firstly let's take a look at how we address different parts of the flash memory. This is relevant for both reading and writing.
Reading data bytes http://img5.imageshack.us/img5/6811/rzz0.png
From page 27 we can see that:
The device is first selected by driving chip select (S#) LOW. The command code for
READ DATA BYTES is followed by a 3-byte address (A23-A0), each bit being latched-in
during the rising edge of serial clock (C).
Why are three bytes required to address the memory? Remember that we have a total of 256 bytes * 4096 pages = 1048576 bytes total. This is equivalent to 2^20, so we would need 20 bits in order to address every byte individually.
There are two good reasons that three bytes are used for the address:
- it aligns the SPI data on a byte boundary, which greatly simplifies the protocol
- it allows larger memory size parts (e.g. 16Mb or 64Mb) to be dropped in as a replacement with minimal changes to your code
Here's the equivalent timing diagram for a write:
Page write timing diagram http://img6.imageshack.us/img6/6973/wwea.png
We can see the 24 bit (3 byte) address followed by a number of data bytes, up to 256 total. Both types of write (PAGE PROGRAM and PAGE WRITE) share these three common characteristics, which are important to address question 1.
If the eight least-significant address bits (A7-A0) are not all zero, all transmitted data
that goes beyond the end of the current page are programmed from the start address of
the same page; that is, from the address whose eight least significant bits (A7-A0) are all
So this suggests that you can address any byte individually in flash memory. You are not constrained to starting at the beginning of a page. If you wish to address byte 913409 you could.
If more than 256 bytes are sent to the device, previously latched data are discarded and
the last 256 data bytes are guaranteed to be programmed correctly within the same
This constraint comes from our page size of 256 bytes. If we write bytes 0..256 (257 total) then the first byte we wrote will be overwritten.
If less than 256 data bytes are sent to device, they are correctly programmed at the
requested addresses without any effects on the other bytes of the same page.
This tells us that we can write less than 256 bytes successfully. We do not need to read 256 bytes, modify them then write back to the device. You can write your 13 bytes, come out of write mode and the other 243 bytes will be unaffected.
However notice from the above that the address only needs to be sent once. It is a starting address, which is then auto-incremented inside the flash part as you write more data. This is our answer to question 1.
PAGE PROGRAM vs. PAGE WRITE
Finally an answer to question 2, which you asked in the comments. Two quotes from the datasheet that explain the difference. For PAGE WRITE:
The PAGE WRITE command allows bytes in the memory to be programmed.
[.. snip ..]
The PAGE WRITE command performs a page erase cycle even if only one byte is updated.
And for PAGE PROGRAM:
The PAGE PROGRAM command allows bytes in the memory to be programmed, which
means the bits are changed from 1 to 0.
The PAGE PROGRAM command is interesting, because it only allows us to change from 1 to 0. When a page is erased the bytes are all set to the default value 0xFF (all binary 1). We can then change some bits back to 0 without incurring the PAGE ERASE, which will eventually wear out the flash (this part is rated to >100k cycles).
Why would this be useful? Well from the timing diagram on page 51 we see the below:
PAGE WRITE vs. PAGE PROGRAM timings http://img689.imageshack.us/img689/1106/9kaj.png
So we can see that PAGE PROGRAM is significantly faster by ~8 times in both typical (11/1.35ms) and max (25/3ms). (Note: this is a very crude comparison as it doesn't include the implicit PAGE ERASE that a PAGE WRITE will always run)
So the answer to question 2 is that PAGE PROGRAM is faster but less flexible.
A fuller discussion can be found in the datasheet under the headings "An easy way to modify data" and "A fast way to modify data".