I'm got a project with an ATTiny424, a UPDI programmer port, and using Microchip Studio in assembly language. I have searched this site and the internet in general and have found a couple routines, but cannot get any of them to work. Can somebody point me in the right direction to a write routine that actually works? I'm only writing 1 byte at a time, to 4 locations (its calibration data for the PCB). I've been working this issue for a couple weeks with no success. Here are the current versions of my routines, originally derived from either here or internet, but have been modifying them to try and get them working. I can write and read - but I fear I am reading the buffer only, because if I reset or power down and just do a read, I get FF every time. The data is not being saved for some reason. HELP!
Here is my current read;
;***************************************************************************
;* EERead
;* r21:r20 = address of data
;* r16 = data
;* Uses Z register pair
;***************************************************************************
EERead:
lds zl, NVMCTRL_STATUS
sbrc zl, NVMCTRL_EEBUSY_bp
rjmp EERead
movw ZH:ZL, r21:r20
ld r16, Z ; read data byte
ret
Here is my current write function;
; EEPROM_write function
; On entry:
; r16:r17 = Adddress of data location
; r18 - byte to be written to EEPROM
; Clobbers:
; zl (r30), zh (r31)
; All other registers preserved
EEPROM_write:
; Wait for completion of previous write
lds zl, NVMCTRL_STATUS
sbrc zl, NVMCTRL_EEBUSY_bp
rjmp EEPROM_write
; sts NVMCTRL_ADDRH, r21
; sts NVMCTRL_ADDRL, r20
movw Z, r16 ;
st Z, r18 ; Store EEPROM data (r18) to write buffer
nop ; Execute NWM erase/write command
cli ; make sure interrupts are disabled for critical section
ldi zl, CPU_CCP_SPM_gc ; unlock NVM command register
ldi zh, 0x03 ; execute NVM erase/write
out CPU_CCP, zl
sts NVMCTRL_CTRLA, zh ;
ret