I want to write bootloader for avr atmega328p in C language. I want to perfom a page erase:
So I have to write the address of the z pointer. // Don't know how to implement in c code; Then make SPMEN AND PGERS bits high. // SPMCSR = (1 << SPMEN) | (1 << PGERS); Then execute SPM instruction within the next 4 clock cycles // Don't know code;
My 1st question is how do I access the Z-register in order to write the address of the page to be erased, Like I have been able to access the SPMCSR register and set the SPMEN and PGERS bits. something like ZPOINTER = 0x00FFEE;
My second question is that, in the datasheet it states that in order to erase the page at a certain address you have to SET the SPMEN and the PGERS bits, then you execute an SPM instruction within the next 4 clock cycles. How do I execute the SPM instruction after setting those aforementioned bits in C code?
Help will be highly appreciated. Thanks. And I throughly searched for similar info on the internet and came with nothing.