The scratchpad is important, because you don't just write directly to the memory. What you do is to write to the scratchpad, then tell the chip to transfer the scratchpad to a chosen memory page. You can however directly read from memory. We have done that and it is simple.
To write to memory, the idea seems to be that you first write to the scratchpad. Then you read that back and verify that it is what you want. Then you transfer the scratchpad to memory.
What it looks like to me is that "read scratchpad" only functions immediately after "write scratchpad". The read command gives back the address information set by the write command and has no way to do anything with it itself.
When I try a "read scratchpad" without a previous write, I get this:
SP 0 0000: 00 - TA1 SP 1 0001: 00 - TA2 SP 2 0002: 9f - E/S status SP 3 0003: ff -- byte 0 SP 4 0004: 58 SP 5 0005: 0d SP 6 0006: 6e SP 7 0007: bf SP 8 0008: ef SP 9 0009: 06 SP 10 000a: 09 -- byte offset 7 SP 11 000b: 43 SP 12 000c: cc SP 13 000d: 11 SP 14 000e: 00 SP 15 000f: 61 SP 16 0010: 00 SP 17 0011: 00 SP 18 0012: 00 SP 19 0013: 00 SP 20 0014: 00 SP 21 0015: 00 SP 22 0016: 00 SP 23 0017: 00 SP 24 0018: 00 SP 25 0019: 00 SP 26 001a: 00 SP 27 001b: 00 SP 28 001c: 00 SP 29 001d: 00 SP 30 001e: 00 SP 31 001f: 00 SP 32 0020: 00 SP 33 0021: ff SP 34 0022: ff -- byte 31 SP 35 0023: ffThe E/S value indicates a full count of 0x1f along with the AA bit being set.
Now I try the example in the datasheet. This first writes 2 bytes to the scratchpad. I write the values 0xab and 0xcd. It writes to the offset 0x26, which is in page 1, offset 6. Then I get this from the read scratchpad command.
SP 0 0000: 26 - read back TA1 SP 1 0001: 00 - read back TA2 SP 2 0002: 07 - read back E/S (ending offset) SP 3 0003: ab - my byte 1 SP 4 0004: cd - my byte 2 SP 5 0005: 43 -- from offset 8 - I should have stopped SP 6 0006: cc SP 7 0007: 11 SP 8 0008: 00 SP 9 0009: 61 SP 10 000a: 00 SP 11 000b: 00 SP 12 000c: 00 SP 13 000d: 00 SP 14 000e: 00 SP 15 000f: 00This actually makes some kind of sense. I am getting back my data from offset 6 and 7 -- then I continue to read and it continues to give me data from the scratchpad (compare to the above where I read out the entire scratchpad by serendipity).
First write to the scratchpad. Give the address (offset) as it you were writing to actual memory. So an offset like 0x26 is intended to ultimately go to page 1, an offset like 0x41 is intended to ultimately go to page 2. Write as many bytes as you like, the chip will keep track of the last offset (ending offset).
Next read from the scratchpad. This is actually optional, but allows you to verify what is in the scratchpad before commiting to the write to memory.
Finally perform the copy scratchpad. This is limited to a single page, and the page is "remembered" from the offset given in the write to scratchpad.
Tom's software pages / tom@mmto.org