• AVR Freaks

Hot!PIC16F15313 NVM programming doesn't work

Author
emarx
Super Member
  • Total Posts : 102
  • Reward points : 0
  • Joined: 2009/05/04 21:53:32
  • Location: 0
  • Status: offline
2020/10/22 08:14:58 (permalink)
0

PIC16F15313 NVM programming doesn't work

Hey All,
 
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

    banksel    NVMADRH
    MOVLW    PROG_ADDR_HI
    MOVWF    NVMADRH ; Load initial address
    MOVF    PROG_ADDR_LO,W
    MOVWF    NVMADRL
    MOVLW    firsteprom ; Load initial data address
    MOVWF    FSR0L
    CLRF    FSR0H
    BCF        NVMCON1,NVMREGS ; Set Program Flash Memory as write location
    BSF        NVMCON1,WREN ; Enable writes
    BSF        NVMCON1,LWLO ; Load only write latches
savecalibloop:
    MOVLW    (firsteprom+epromdataread)
    SUBWF    FSR0L,W        ;carry if reached the last data
    MOVF    INDF0,W
    BTFSC    STATUS,C
    MOVLW    0xFF        ;if reached the last RAM data, just load NVM cells with FF (erase data)
    BTFSS    STATUS,C
    INCF    FSR0L        ;Go to next data if haven't reached the last one.
    MOVWF    NVMDATL ; Load first data byte
    MOVLW    0x00
    MOVWF    NVMDATH ; Load second data byte, always zero
    MOVF    NVMADRL,W
    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
    GOTO    savecalibloop
start_write:
    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
unlock_seq:
    BCF        INTCON,GIE ; Disable interrupts
    MOVLW    0x55
    MOVWF    NVMCON2 ; Begin unlock sequence
    MOVLW    0xAA
    MOVWF    NVMCON2
    BSF        NVMCON1,WR
    BSF INTCON,GIE ; Unlock sequence complete, re-enable interrupts
    RETURN
#1

3 Replies Related Threads

    davea
    Super Member
    • Total Posts : 500
    • Reward points : 0
    • Joined: 2016/01/28 13:12:13
    • Location: Tampa Bay FL USA
    • Status: offline
    Re: PIC16F15313 NVM programming doesn't work 2020/10/22 13:01:16 (permalink)
    0
    EXAMPLE 13-3: ERASING ONE ROW OF PROGRAM FLASH MEMORY (PFM)
    ; This sample row erase routine assumes the following:
    ; 1.A valid address within the erase row is loaded in variables ADDRH:ADDRL
    ; 2.ADDRH and ADDRL are located in common RAM (locations 0x70 - 0x7F)
    ///switch banks back and forth to not use common RAM
    BANKSEL NVMADRL
    MOVF ADDRL,W
    MOVWF NVMADRL ; Load lower 8 bits of erase address boundary
    MOVF ADDRH,W
    MOVWF NVMADRH ; Load upper 6 bits of erase address boundary
    BCF NVMCON1,NVMREGS ; Choose PFM memory area
    BSF NVMCON1,FREE ; Specify an erase operation
    BSF NVMCON1,WREN ; Enable writes
    BCF INTCON,GIE ; Disable interrupts during unlock sequence
    ; -------------------------------REQUIRED UNLOCK SEQUENCE:------------------------------
    MOVLW 55h ; Load 55h to get ready for unlock sequence
    MOVWF NVMCON2 ; First step is to load 55h into NVMCON2
    MOVLW AAh ; Second step is to load AAh into W
    MOVWF NVMCON2 ; Third step is to load AAh into NVMCON2
    BSF NVMCON1,WR ; Final step is to set WR bit
    ; --------------------------------------------------------------------------------------
    BSF INTCON,GIE ; Re-enable interrupts, erase is complete
    BCF NVMCON1,WREN ; Disable writes

    is this in your code somewhere?
    did you try page 163 as is
     
     
    #2
    emarx
    Super Member
    • Total Posts : 102
    • Reward points : 0
    • Joined: 2009/05/04 21:53:32
    • Location: 0
    • Status: offline
    Re: PIC16F15313 NVM programming doesn't work 2020/10/22 17:38:25 (permalink)
    +1 (1)
    Haha I see the problem already...
     
      MOVF    PROG_ADDR_LO,W
     
    should be
     
      MOVLW    PROG_ADDR_LO
     
    sorry to bother everyone with this...
     
    #3
    Hen
    Super Member
    • Total Posts : 114
    • Reward points : 0
    • Joined: 2018/10/24 04:01:44
    • Location: 0
    • Status: offline
    Re: PIC16F15313 NVM programming doesn't work 2020/10/22 21:04:52 (permalink)
    +3 (3)
    emarx
    sorry to bother everyone with this...

    The forum says, de nada Smile: Smile
     
    Once one tries to describe problems to others, solutions may come out from hiding from another part of the brain.
    #4
    Jump to:
    © 2020 APG vNext Commercial Version 4.5