EasyManuals Logo

Atmel AVR User Manual

Atmel AVR
191 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #169 background imageLoading...
Page #169 background image
116. SPM – Store Program Memory
116.1. Description
SPM can be used to erase a page in the Program memory, to write a page in the Program memory (that
is already erased), and to set Boot Loader Lock bits. 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)
. When setting the Boot Loader Lock bits, the R1:R0 register pair is used as
data. Refer to the device documentation for detailed description of SPM usage. This instruction can
address the entire Program memory.
The SPM instruction is not available in all devices. Refer to the device specific instruction set summary.
Note:  1. R1 determines the instruction high byte, and R0 determines the instruction low byte.
Operation:
(i) (RAMPZ:Z) ← $ffff Erase Program memory page
(ii) (RAMPZ:Z) ← R1:R0 Write Program memory word
(iii) (RAMPZ:Z) ← R1:R0 Write temporary page buffer
(iv) (RAMPZ:Z) ← TEMP Write temporary page buffer to Program
memory
(v) BLBITS ← R1:R0 Set Boot Loader Lock bits
Syntax: Operands: Program Counter:
(i)-(v) SPM Z+ PC ← PC + 1
16-bit Opcode:
1001 0101 1110 1000
116.2. Status Register (SREG) and Boolean Formula
I T H S V N Z C
Example:
;This example shows SPM write of one page for devices with page write
;- the routine writes one page of data from RAM to Flash
; the first data location in RAM is pointed to by the Y-pointer
; the first data location in Flash is pointed to by the Z-pointer
;- error handling is not included
;- the routine must be placed inside the boot space
; (at least the do_spm sub routine)
;- registers used: r0, r1, temp1, temp2, looplo, loophi, spmcrval
Atmel AVR Instruction Set Manual [OTHER]
Atmel-0856L-AVR-Instruction-Set-Manual_Other-11/2016
169

Table of Contents

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the Atmel AVR and is the answer not in the manual?

Atmel AVR Specifications

General IconGeneral
Architecture8-bit RISC
SRAMUp to 16 KB
Clock SpeedUp to 20 MHz
Operating Voltage1.8V to 5.5V
ADC10-bit ADC
Communication InterfacesSPI, I2C, USB
PackagesDIP, SOIC, QFN
Special FeaturesWatchdog Timer
Flash Memory1KB to 256KB
EEPROM64B to 4KB

Related product manuals