6.113.1 Description

SPM can be used to erase a page in the program memory and to write a page in the program memory (that is already erased). In some devices, the program memory can be written one word at a time. In other devices, an entire page can be programmed simultaneously after first filling a temporary page buffer. In all cases, the program memory must be erased one page at a time. When erasing the program memory, the RAMPZ and Z-register are used as page address. When writing the program memory, the RAMPZ and Z-register are used as page or word address, and the R1:R0 register pair is used as data(1). The Flash is word-accessed for code space write operations, so the least significant bit of the RAMPZ register concatenated with the Z register should be set to ‘0’.

Refer to the device documentation for a detailed description of SPM usage. This instruction can address the entire program memory.

The SPM instruction is not available on all devices. Refer to Appendix A.

Note: 1. R1 determines the instruction high byte, and R0 determines the instruction low byte.

Operation:

(i)

PS(RAMPZ:Z) ← 0xffff

Erase program memory page

(ii)PS(RAMPZ:Z) ← R1:R0Write to program memory word(1)

(iii)

PS(RAMPZ:Z) ← R1:R0

Load Page Buffer(2)

(iv)

PS(RAMPZ:Z) ← BUFFER

Write Page Buffer to program memory(2)

(v)

PS(RAMPZ:Z) ← 0xfff, Z ← Z + 2

Erase program memory page, Z post incremented

(vi)PS(RAMPZ:Z) ← R1:R0, Z ← Z + 2Write to program memory word, Z post incremented(1)

(vii)

PS(RAMPZ:Z) ← R1:R0, Z ← Z + 2

Load Page Buffer, Z post incremented(2)

(viii)

PS(RAMPZ:Z) ←BUFFER, Z ← Z + 2

Write Page Buffer to program memory, Z post incremented(2)

Syntax:

Operands:

Program Counter:

(i)-(iv)

SPM

None

PC ← PC + 1

(v)-(viii)

SPM Z+

None

PC ← PC + 1

Note:
  1. Not all devices can write directly to program memory, see device data sheet for detailed description of SPM usage.
  2. Not all devices have a page buffer, see device data sheet for detailed description of SPM usage.

16-bit Opcode:

(i)-(iv)1001010111101000
(v)-(viii)1001010111111000