Announcement

Collapse
No announcement yet.

writing serial number to 18f27k40

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • writing serial number to 18f27k40

    Hi charles

    it appears i am unable to write a serial number to eeprom using the u2 programmer for this chip

    i am using start address of F0000A ( byte 9,10 , 2 locations , msb first

    cheers

    Sheldon


  • #2
    software ver is 4.64

    via iscp

    Comment


    • #3
      Try start address 31000A.
      Charles Leo
      ME Labs, Inc.
      http://melabs.com

      Comment


      • #4
        no luck, same result

        Comment


        • #5
          wondering if any config of pic setting , such as eeprom write enable would effect this , the config is not se to lock down the eeprom but just asking

          Comment


          • #6
            Looking through the Data Sheet, it appears there are a couple requirements spelled out in different sections. First, writing to User ID is writing to NVM. Section 11.2.2 states: "The WREN bit in NVMCON1 must be set to enable writes." Next, "The user needs to load the TBLPTR and TABLAT reg- ister with the address and data byte respectively before executing the write command." And finally, "An unlock sequence needs to be followed for writing to the USER IDs..."

            Table 11-4 lists the User ID Addresses as 20 0000h through 20 000Fh, 8 addresses available.

            Section 11.1 covers reads & writes to NVM with ASM examples given. I've never tried using the User ID section. However, I have written to the HEF on PIC16's. I'm guessing it's a similar process. Here is the code used:

            Code:
            HeF_START   CON     8064            ;0X1F80    START ADDRESS OF HE_FLASH to use [start of row] for PIC16 HEF, 20 0000h for the K40 User ID section
            N_HeF_V     CON     14              ;NUMBER OF HE_FLASH WORD VARS, number of bytes used in your Serial Number?
            
            heFvar      var     WORD[N_HeF_V]       ;SRAM COPIES OF  HE_FLASH  VARS
            hefx        var     byte                ;USED IN ASM  to index   HE_FLASH  VARS
            RESULT      var     WORD[4]             ;Buffer for HEF Read
            
            Write_HEF:
                heFvar[0] = DacL
                heFvar[1] = DacH
                heFvar[2] = HhoStat
                heFvar[3] = Amp_Targ
            ; ...and so forth
            ASM
                CALL    FLERASE                         ; WARNING ENTIRE ROW IS ERASED BEFORE WRITE
                movlw   _N_HeF_V
                BANKSEL _hefx
                MOVWF   _hefx
                BANKSEL _heFvar
                movlw   LOW  _heFvar
                MOVWF   FSR0L
                movlw   HIGH _heFvar
                MOVWF   FSR0H
                BANKSEL PMADRH
                MOVLW   HIGH (_HeF_START)
                MOVWF   PMADRH                        
                MOVLW   LOW  (_HeF_START)
                MOVWF   PMADRL                     
                BCF     PMCON1,CFGS
                BSF     PMCON1,WREN
                BSF     PMCON1,LWLO
                BCF     PMCON1,FREE
            LOOP
                MOVIW   FSR0++                          ; Load  data byte into lower
                MOVWF   PMDATL                          ;
                MOVIW   FSR0++                          ; Load  data byte into upper
                MOVWF   PMDATH                          ;
                BANKSEL _hefx
                DECF    _hefx,F
                BTFSC   STATUS,Z
                GOTO    START_WRITE
                CALL    ULOC
                ;BANKSEL PMADRL
                INCF    PMADRL,F                        ; Still loading latches Increment address
                GOTO    LOOP                            ; Write next latches
            START_WRITE
                BANKSEL PMCON1  
                BCF     PMCON1,LWLO
                CALL    ULOC
                ;BANKSEL PMCON1
                BCF     PMCON1,WREN
                BANKSEL 0
                RETURN  
            ULOC
                BANKSEL PMCON2
                MOVLW   55h                             ; Start of required write sequence:
                MOVWF   PMCON2 & 0x7F                   ; Write 55h
                MOVLW   0xAA                            ;
                MOVWF   PMCON2 & 0x7F                   ; Write AAh
                BSF     PMCON1 & 0x7F,WR                ; Set WR bit to begin write
                NOP                                     ; NOP instructions are forced as processor
                NOP                                     ; loads program memory write latches  
                RETURN
            FLERASE
                CLRWDT   
                BANKSEL PMADRL
                MOVLW   HIGH (_HeF_START)
                MOVWF   PMADRH                        
                MOVLW   LOW  (_HeF_START)
                MOVWF   PMADRL 
                BCF     PMCON1,CFGS                     ; Not configuration space
                BSF     PMCON1,FREE                     ; Specify an erase operation
                BSF     PMCON1,WREN                     ; Enable writes
                MOVLW   55h                             ; Start of required sequence to initiate erase
                MOVWF   PMCON2                          ; Write 55h
                MOVLW   0AAh                            ;
                MOVWF   PMCON2                          ; Write AAh
                BSF     PMCON1,WR                       ; Set WR bit to begin erase
                NOP                                     ; NOP instructions are forced as processor starts
                NOP                                     ; row erase of program memory.
                BCF     PMCON1,WREN                     ; Disable writes
                ;BANKSEL 0
                RETURN
            endasm
            Hope this helps
            We can crack this cotton PIC'n thang!

            Comment


            • #7
              thanks mike , currency i use the u2 programmer to write the serial number to EEprom when doing the programing via ISCP

              up to now its only been a mater of getting the start addres correct , as long as the programmer supports the chip ,

              i used to write to the user id area , but this failed to on the u2 programmer for the k22 series , on any write after the first write , and it was flagged by darrel as a fix on the programmer firmware at the time

              so moved serial number to the eeprom

              as the 27k40 does have more protection of the program area , and prom area than previous chips,

              that an extra step the U2 programmer must do to allow writing to the EEprom area , but i am guessing

              hope charles can check into it

              cheers

              Sheldon

              Comment


              • #8
                It works for me using starting address 31000A, but the data shows up at 0005 in data space instead of 000A. Use address 310014 to place the data at 000A in data space.

                I tested with software version 4.64.
                Charles Leo
                ME Labs, Inc.
                http://melabs.com

                Comment


                • #9
                  thanks charles ,
                  so start address of eeprom is 310005 hex , wonder why its not 310000hex ?

                  Comment


                  • #10
                    The start address is 310000. I thought you were using an offset from the start address.
                    Charles Leo
                    ME Labs, Inc.
                    http://melabs.com

                    Comment


                    • #11
                      i am and the address of 310014 works correctly for start location A, for the eeprom

                      but its seem strange that if i want the write address 0 in eeprom that i would put in 310005 as the start address

                      Comment

                      Working...
                      X