• AVR Freaks

AnsweredHot!PIC18F27K42 EEPROM PROBLEM

Author
_pike
Senior Member
  • Total Posts : 145
  • Reward points : 0
  • Joined: 2012/12/02 11:34:43
  • Location: 0
  • Status: offline
2020/02/21 12:12:09 (permalink)
0

PIC18F27K42 EEPROM PROBLEM

Hello experts! I am having a problem with the internal eeprom of 18f27k42. Its a weird problem and i have faced a dead end.
I have successully read and written the internal eeprom of the pic.
I want on power up, to check if the eeprom is blank, and if so.... to write a pre-defined table at the eeprom....
So on power loss when it will initializes again, if it sees that the eeprom is not blank to skip the process of writting at it.
Below is the code.....
 

   
EEPROM_INIT DB "ADMIN+1234",0,"GUEST1+2345",0,"GUEST2+3456",0,"GUEST3+4567",0,"GUEST4+5678",0,"GUEST5+6789",0  
 
 
EEPROM_INITIAL_WRITE:

   ; CALL EEPROM_BEGINNING
   ; CALL EEPROM_READ       
   ;  MOVLW 0XFF
   ;  CPFSEQ NVMDAT  
   ;  RETURN          
NEXT_BYTE_2:
     CALL EEPROM_BEGINNING
    MOVLW .6
    MOVWF USERS
   LOADTABLE EEPROM_INIT
NEXT_BYTE: 
    TBLRD*+             ; READ THE CHARACTER AND INCREASE  
    MOVF TABLAT, W
    CALL EEPROM_WRITE_BYTE
    TSTFSZ TABLAT     ; IF WE PLACE IT HERE WE ALSO WRITE THE 0X00
    BRA NEXT_BYTE
    DECFSZ USERS,F
    BRA NEXT_BYTE
    RETURN
    

EEPROM_WRITE_BYTE:
 
    CLRF NVMCON1    ; Setup Data EEPROM Access
    INCF NVMADRL,F    ; Setup Address  WE PLAY ONLY WITH THE LOW PORTION OF THE REGISTER SINCE WE WILL NOT EXCEED 255 BYTES
    MOVWF NVMDAT ;
    BSF NVMCON1, WREN    ; Enable writes
    MOVLW 0X55        ; Required unlock sequence
    MOVWF NVMCON2    ;
    MOVLW 0XAA        ;
    MOVWF NVMCON2    ;
    BSF NVMCON1, WR    ; Set WR bit to begin write
    BTFSC NVMCON1,WR
    BRA $-2
    BCF NVMCON1, WREN    ; Disable writes
    RETURN
    
    
EEPROM_BEGINNING:  
    BANKSEL NVMADRH
    CLRF NVMADRH  ; Setup Address
    MOVLW .255
    MOVWF NVMADRL ; Setup Address
    RETURN
    
    
EEPROM_READ:
    
    CLRF NVMCON1 ; Setup Data EEPROM Access
    INCF NVMADRL ; Setup Address
    BSF NVMCON1, RD ; Issue EE Read
    BTFSC NVMCON1,RD
    BRA $-2
    MOVF NVMDAT, W ; W = EE_DATA
    RETURN
   

 
If i remove the comment ; from the first 5 lines i have the problem that it is shown on the second photo.
 
The first photo shows the successfull writing of the table...
The second photo shows the problem that i have and i cant still figure out....
 
 
Thank you very much!!!!

Attached Image(s)

#1
1and0
Access is Denied
  • Total Posts : 10783
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: PIC18F27K42 EEPROM PROBLEM 2020/02/21 13:11:33 (permalink)
0
_pike
I want on power up, to check if the eeprom is blank, and if so.... to write a pre-defined table at the eeprom....

Look up the DE directive.
 

So on power loss when it will initializes again, if it sees that the eeprom is not blank to skip the process of writting at it.

Why initialize the EEPROM on power loss (power down)?
 
 
#2
ric
Super Member
  • Total Posts : 27071
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: offline
Re: PIC18F27K42 EEPROM PROBLEM 2020/02/21 14:07:41 (permalink) ☼ Best Answerby _pike 2020/02/22 16:33:49
+2 (2)
_pike, do you have BOR enabled?
If not, depending upon your power supply power-on characteristics,  if your code starts reading EEPROM straight after power on, it may access it before Vdd reaches sufficient levels. That is known to sometimes turn a read into a write.
As a safety measure, I NEVER attempt to read EEPROM until multiple 100ms after power on.
 
As 1and0 mentioned, why not just use the DE directive to set the initial value?
That is a MUCH better way to get the same functionality.
 

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#3
_pike
Senior Member
  • Total Posts : 145
  • Reward points : 0
  • Joined: 2012/12/02 11:34:43
  • Location: 0
  • Status: offline
Re: PIC18F27K42 EEPROM PROBLEM 2020/02/22 17:01:56 (permalink)
+2 (2)
Hello my friends!!! Problem solved !!! Thank you BOTH for your concern....!!!
Richard the problem was caused because of the delay that you said... adding a delay fixed the problem!!!
(didnt know that, couldnt imagine it also,althought that it should be in the datasheet on timing charts i suppose.)
Harry pickit4 and mplabx has blown my head... All of this was happened because you cannot write straight forward at eeprom as we used to... I wanted to have initial users stored on eeprom, but every time that the pic would lose power, on startup, if a user had stored a new password (before power loss) the routine would write again the default values on startup so it would lose user's new entry... But i dont regret it since i learnt something new...!!!
Also when i perform a read device when it finishes the read operation, the pickit4 keeps the pic in halt mode? i cant understand why.... but i have to disconnect it to start running the programm
My friend had told me once...
"Concern each failure as a valuable lesson... for if you don't find out how something will work,you definately found how it doesn't..."
 
Thank you again very much !!!
 
<edit> By saying use the DE directive, you mean replacing the DB with DE ,or it needs further manipulation?
 
 
post edited by _pike - 2020/02/22 17:13:42
#4
1and0
Access is Denied
  • Total Posts : 10783
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: PIC18F27K42 EEPROM PROBLEM 2020/02/22 17:58:21 (permalink) ☄ Helpfulby _pike 2020/02/23 13:52:51
0
_pike
By saying use the DE directive, you mean replacing the DB with DE ,or it needs further manipulation?

To initialize EEPROM data on a PIC18 K42 device do this:
    org     0x310000
    de      "ADMIN+1234",0,"GUEST1+2345",0,"GUEST2+3456",0,"GUEST3+4567",0,"GUEST4+5678",0,"GUEST5+6789",0

for absolute code, or this
    code   0x310000
    de     "ADMIN+1234",0,"GUEST1+2345",0,"GUEST2+3456",0,"GUEST3+4567",0,"GUEST4+5678",0,"GUEST5+6789",0

for relocatable code. These data will be programmed into the EEPROM when the PIC device is programmed.
#5
ric
Super Member
  • Total Posts : 27071
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: offline
Re: PIC18F27K42 EEPROM PROBLEM 2020/02/23 01:50:15 (permalink)
+1 (1)
Did you try just turning BOR on?
I would stongly recommend you do.
 

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#6
_pike
Senior Member
  • Total Posts : 145
  • Reward points : 0
  • Joined: 2012/12/02 11:34:43
  • Location: 0
  • Status: offline
Re: PIC18F27K42 EEPROM PROBLEM 2020/02/23 14:10:21 (permalink)
0
You are fantastic !!! very helpful!!!
Well in configuration bits there are 3 main choices  :
 
LPBOREN => ON , OFF
BOREN => SBORDIS , NOSLP , ON , OFF
BORV =>  VBOR_190 ,  VBOR_245 ,  VBOR_2P7 ,  VBOR_2P85
 
As it is obvious i should turn LPBOREN => "on"   but what voltage should i select? I use (L)F chip.
Also i cannot understand sbordis selection it says "brown out select enabled sboren bit is ignored" What does this mean?
 
Thank you!!
#7
ric
Super Member
  • Total Posts : 27071
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: offline
Re: PIC18F27K42 EEPROM PROBLEM 2020/02/23 14:20:21 (permalink)
+1 (1)
I wouldn't touch LPBOREN unless you're running an ultra low power always on circuit.
Just use the normal BOREN.
What voltage is Vdd when your board is running normally?
5V? 3.3V? 2.5V? Something else?
 
You should read about the SBOREN bit in your datasheet to find out what that does.
 

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#8
_pike
Senior Member
  • Total Posts : 145
  • Reward points : 0
  • Joined: 2012/12/02 11:34:43
  • Location: 0
  • Status: offline
Re: PIC18F27K42 EEPROM PROBLEM 2020/02/23 14:30:49 (permalink)
0
Ok i understand!!   The voltage is 3.3v
I also tried the org 0x310000 which worked like a charm.... but the code 0x310000 fails followed by this message...
 
Error - section '.code' type is non-overlay and absolute but occurs in more than one input file.
Errors    : 1
 
I use relocatable mode with more than one *.asm files for my project.
#9
ric
Super Member
  • Total Posts : 27071
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: offline
Re: PIC18F27K42 EEPROM PROBLEM 2020/02/23 14:48:59 (permalink)
+1 (1)
_pike
Ok i understand!!   The voltage is 3.3v

I'd use the highest available BOR voltage then.
2.85 is still 0.45 below your operating voltage.
 

I also tried the org 0x310000 which worked like a charm.... but the code 0x310000 fails followed by this message...
 
Error - section '.code' type is non-overlay and absolute but occurs in more than one input file.
Errors    : 1
 
I use relocatable mode with more than one *.asm files for my project.

That means it is encountering the ORG statement more than once.
Is it in an ASM file, or in some file included by an ASM file.
How are you using multiuple files? Listing them all in the "source files" folder in the project, or including them into another file (or both, which is very very wrong)
 

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#10
1and0
Access is Denied
  • Total Posts : 10783
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: PIC18F27K42 EEPROM PROBLEM 2020/02/23 15:16:03 (permalink) ☄ Helpfulby _pike 2020/02/24 14:15:50
+1 (1)
_pike
I also tried the org 0x310000 which worked like a charm.... but the code 0x310000 fails followed by this message...
 
Error - section '.code' type is non-overlay and absolute but occurs in more than one input file.
Errors    : 1

Give it a section name and see:
dataeep code    0x310000
        de      "ADMIN+1234",0,"GUEST1+2345",0,"GUEST2+3456",0,"GUEST3+4567",0,"GUEST4+5678",0,"GUEST5+6789",0

#11
_pike
Senior Member
  • Total Posts : 145
  • Reward points : 0
  • Joined: 2012/12/02 11:34:43
  • Location: 0
  • Status: offline
Re: PIC18F27K42 EEPROM PROBLEM 2020/02/24 14:14:20 (permalink)
0
Hello guys!! Well it worked by placing a name!!! Can you please explain it to me why this error pop up? And how it works just by placing a label?
Well this is how i am using multiple *.asm files.....
In a previous thread we had a conversation of how libraries are made... and you told me that by making an *.inc file and then include it in the main is not the right way to connect a library... So what i did, was to create *.asm files for each module i use, and allow the linker to do the connection between the main asm with the asm that has to do with the modules.
But as far as i can understand you say that this is also wrong.... 
#12
ric
Super Member
  • Total Posts : 27071
  • Reward points : 0
  • Joined: 2003/11/07 12:41:26
  • Location: Australia, Melbourne
  • Status: offline
Re: PIC18F27K42 EEPROM PROBLEM 2020/02/24 14:19:37 (permalink)
0
No, it's correct. I was saying not to do BOTH.
Adding the name just moves that section to the new address. I guess leaving it unnamed moves all following unnamed sections up there too.
 

I also post at: PicForum
Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
NEW USERS: Posting images, links and code - workaround for restrictions.
To get a useful answer, always state which PIC you are using!
#13
1and0
Access is Denied
  • Total Posts : 10783
  • Reward points : 0
  • Joined: 2007/05/06 12:03:20
  • Location: Harry's Gray Matter
  • Status: offline
Re: PIC18F27K42 EEPROM PROBLEM 2020/02/24 23:21:20 (permalink)
0
_pike
Hello guys!! Well it worked by placing a name!!! Can you please explain it to me why this error pop up? And how it works just by placing a label?

An absolute section with the same name may only occur in a single input file, since a object file section must be contiguous. The default section name for the CODE directive is .code when it's unnamed. That error message means there are multiple absolute sections with the same .code name in the source files. So, naming the sections with different names fixes that error.
 
#14
Jump to:
© 2020 APG vNext Commercial Version 4.5