Skip to main content
1 of 4

Question on Page erase and page write using SPM instruction for ATmega328

I have been studying this for ATmega328, I first want to verify I am correct in the following. And then I have question on page write and page erase.

  1. ATmega328 has 32K byte flash = 16K words. It is organized as 256Pages with 64Words/pages.

  2. So you need 6 address bits for each page(64Words/page), You need 8 address bits to address 256Page.

  3. For ATmega328, you don’t need RAMPZ register. Use Z(6..1) as WORD address within each page. Use Z(14..7) as PAGE address. Z15 and Z0 NOT USED.

I have question about SPM instruction. It supposedly can write ONE WORD or ONE PAGE. It can ERASE ONE PAGE. I really don’t know how it works. I’ve been searching and I cannot find answer.

enter image description here

In the copy above.

  1. If I don’t have RAMPZ, it should be just (Z) instead of (RAMPZ:Z)?

  2. As above because the address is for word(not byte), Z0 is not used. I don’t understand how they can write Z+, you have to increment 2 times to increment Z1 by 1.

  3. How do you do a page erase as shown in (i) above? In my case it should be (Z)$ffff. How is that erase a full page of 64Words. What is the Syntax using SPM instruction.

  4. What is the Syntax o f(ii) to write one word using SPM?

  5. How do you set up to write one page of program memory from temporary page in (iv) using SPM?

I have been searching around with no luck.

Thanks