10.3.2.3 Command Modes

Reading the memory arrays is handled using the LD*/LPM(*) instructions.

Erasing the entire Flash (CHER) or EEPROM (EECHER) is started by writing commands to the Control A (CTRLA) register. The other write/erase operations are only enabled by writing commands to the CTRLA register and must be followed by writes using ST*/SPM(*) instructions to the memory arrays.
Note: * LPM/SPM cannot be used for EEPROM.
The following sequence must execute to write a command in the CTRLA register:
  1. Confirm that any previous operation is completed by reading the Busy (EEBUSY and FBUSY) flags in the STATUS register.
  2. Write the appropriate key to the Configuration Change Protection (CPU.CCP) register to unlock the Control A (NVMCTRL.CTRLA) register.
  3. Write the desired command value to the CMD bit field in the Control A (NVMCTRL.CTRLA) register within the following four instructions.
The following steps are required to perform a write/erase operation in the NVM:
  1. Confirm that any previous operation is completed by reading the Busy (EEBUSY and FBUSY) flags in the STATUS register.
  2. Optional: If accessing the Flash in the CPU data space, map the corresponding 32 KB Flash section into the data space by writing the FLMAP bit field in the CTRLB register.
  3. Write the desired command value to the CTRLA register as described before.
  4. Write to the correct address in the data space/code space using the ST*/SPM instructions.
  5. Optional: If multiple write operations are required, go to step 4.
  6. Write a NOOP or NOCMD command to the CTRLA register to clear the current command.