PIC16F15313 NVM programming doesn't work
Hopefully someone using the NVM on the PIC16F15313 has experience with this?
I'm having an awful lot of trouble with the NVM on the 16F15313 chip. It seems there is something basic that I am missing. Read and Erase operations seem to work, but the write doesn't work. I thought maybe it's because I disabled low voltage programming, but my understanding is this only affects external programming, correct?
I'm especially confused since I'm looking on pages 162 and 163 of the specification, and they have 2 discrepancies:
1) P. 162 refers to TBLPTR but I assume it is referring to NVMADRL?
2) P. 163 "slides" into UNLOCK_SEQ the last time without explicitly calling the subroutine?
Anyways here is my EPROM writing subroutine which doesn't seem to work:
firsteprom equ 0xDC
epromdataread equ 0x12
MOVWF NVMADRH ; Load initial address
MOVLW firsteprom ; Load initial data address
BCF NVMCON1,NVMREGS ; Set Program Flash Memory as write location
BSF NVMCON1,WREN ; Enable writes
BSF NVMCON1,LWLO ; Load only write latches
SUBWF FSR0L,W ;carry if reached the last data
MOVLW 0xFF ;if reached the last RAM data, just load NVM cells with FF (erase data)
INCF FSR0L ;Go to next data if haven't reached the last one.
MOVWF NVMDATL ; Load first data byte
MOVWF NVMDATH ; Load second data byte, always zero
XORLW 0x1F ; Check if lower bits of address are 00000
ANDLW 0x1F ; and if on last of 32 addresses
BTFSC STATUS,Z ; Last of 32 words?
GOTO start_write ; If so, go write latches into memory
CALL unlock_seq ; If not, go load latch
INCF NVMADRL,F ; Increment address
BCF NVMCON1,LWLO ; Latch writes complete, now write memory
CALL unlock_seq ; Perform required unlock sequence
BCF NVMCON1,WREN ; Disable writes
RETURN ;***Last "unlock_seq" is probably a mistake in the documentation
BCF INTCON,GIE ; Disable interrupts
MOVWF NVMCON2 ; Begin unlock sequence
BSF INTCON,GIE ; Unlock sequence complete, re-enable interrupts