Searching \ for '[PIC]: 16f628 EEPROM woes' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/memory.htm?key=eeprom
Search entire site for: '16f628 EEPROM woes'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]: 16f628 EEPROM woes'
2004\06\14@004550 by andrew n1yew

picon face
Hello all,

I'm back after a break =P.. I'm going to college this year in the fall, I
got a PicStart Plus and that works well.

To the point: I have some 628's (not the A revision), and I can't seem to
write to the ee (using pic code, but I can read it if I wrote it with the
programmer.) I am using the following code (bank0/1 work properly, or else i
couldnt have setup my ports):

<snip>
movfw al    ;my ptr counter
 movwf EEADR
 call rrs232
 bank1
 movwf  EEDATA
 bank0
 call  wr_ee

 call  rd_ee    ;this reads properly.. like if i already had contents in EE
 bank1
 movfw  EEDATA
 bank0
 call  srs232
</snip>
<snip>
wr_ee  bank1
 bsf  EECON1,WREN
 bcf  INTCON,GIE
 movlw  0x55
 movwf  EECON2
 movlw  0xaa
 movwf  EECON2
 bsf  EECON1,WR
 bank0

 btfss  PIR1,EEIF
 goto  $-1

 bcf  PIR1,EEIF
 bank1
 bcf  EECON1,WREN
 bank0
 return
</snip>

thanks, its really confusing me.. and I am looking at the latest data sheet
which shows all EE SFRs are in bank1.

--andrew

--
http://www.piclist.com hint: To leave the PICList
spam_OUTpiclist-unsubscribe-requestTakeThisOuTspammitvma.mit.edu

2004\06\14@013047 by Jinx

face picon face
>   movfw al    ;my ptr counter
>   movwf EEADR
>   call rrs232
>   bank1
>   movwf  EEDATA
>   bank0
>   call  wr_ee

EEADR (9B) and EEDATA (9A) are both in Bank1. If you're
in Bank0 at "movwf EEADR" then you'll be writing to 1B

You try this for writing

write    bsf     eecon1,wren
        movlw   0x55
        movwf   eecon2
        movlw   0xaa
        movwf   eecon2
        bsf     eecon1,wr
        nop

wrend    btfsc   eecon1,wr
        goto    wrend
        bank0

--
http://www.piclist.com hint: To leave the PICList
.....piclist-unsubscribe-requestKILLspamspam@spam@mitvma.mit.edu

2004\06\14@140505 by Bob Axtell

face picon face
After you get it writing & Reading, you need to be aware that there are
cases where the EEROM data seems to drop out on the PIC nanoWatt devices
after a few days.

I've had to write several copies of the data (plus checksum) and then
check the checksum before using the data, finding a GOOD copy of the
data, then overwite the bad copies.

Not sure what that is all about; only occurs on NanoWatt series parts...

--Bob

Jinx wrote:

{Quote hidden}

--

Replier: Most attachments rejected
      --------------
        Bob Axtell
PIC Hardware & Firmware Dev
  http://beam.to/baxtell
      1-520-219-2363

--
http://www.piclist.com hint: To leave the PICList
.....piclist-unsubscribe-requestKILLspamspam.....mitvma.mit.edu

2004\06\14@185153 by Jinx

face picon face
> After you get it writing & Reading, you need to be aware that there
> are cases where the EEROM data seems to drop out on the PIC
> nanoWatt devices after a few days

Is that documented anywhere ?

--
http://www.piclist.com hint: To leave the PICList
EraseMEpiclist-unsubscribe-requestspam_OUTspamTakeThisOuTmitvma.mit.edu

2004\06\15@082512 by andrew n1yew

picon face
Jinx, I tried that write code segment and that didn't work also.  I also
tried writing static data and reading it out but that didn't work either..
maybe my chip is screwed up? Also, I tried writing to it with the programmer
and reading it back with the programmer but it came back as 00's.. I don't
believe code protect is set, but I'll double check.

thanks,
andrew

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2004\06\15@092501 by Jinx

face picon face
> Jinx, I tried that write code segment and that didn't work also

I'm certain the code is fine. This is what I'm using currently on the
18F452 and it works OK. It's the 18F equivalent of the 628 code

save    bsf     eecon1,wren   ;enable write
        mov     0x55,eecon2
        mov     0xaa,eecon2
        bsf     eecon1,wr     ;initiate write cycle

wrend   btfsc   eecon1,wr     ;wait for WR bit to clear
        bra     wrend2
        bcf     eecon1,wren
        return

> Also, I tried writing to it with the programmer and reading it back
> with the programmer but it came back as 00's

Trying another 628 should tell you what's going on

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2004\06\15@094141 by Buehler, Martin

picon face
i used the 628 for 2 projects, and writing to eeprom has never been
reliable. that's why I don't use the 628 anymore...
tino

************************************************************************
******************************

>{Original Message removed}

2004\06\15@162647 by andrew n1yew

picon face
----- Original Message -----
From: "Jinx" <joecolquittspamspam_OUTCLEAR.NET.NZ>
To: <@spam@PICLISTKILLspamspamMITVMA.MIT.EDU>
Sent: Tuesday, June 15, 2004 9:26 AM
Subject: Re: [PIC]: 16f628 EEPROM woes


{Quote hidden}

nope, I tried also just writing and reading back.. which didn't work..

> Trying another 628 should tell you what's going on

yeah, I tried three.. all out of the same tube.. datestamp 040438H

any clues? maybe the 628's have an issue with ee?

-andrew

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2004\06\15@163724 by William Bross

picon face
Andrew,

Are you always branching to wrend2 or wrend?  Is that a typo or are you
trying to go somewhere else?

Bill

{Original Message removed}

2004\06\15@164724 by andrew n1yew

picon face
> Are you always branching to wrend2 or wrend?  Is that a typo or are you
> trying to go somewhere else?
<snip>
> > wrend   btfsc   eecon1,wr     ;wait for WR bit to clear
> >          bra     wrend2
> >          bcf     eecon1,wren
> >          return
</snip>

yes it was a typo.. It's supposed to sit there until it is clear..

andrew

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2004\06\15@192501 by Jinx

face picon face
> Are you always branching to wrend2 or wrend?  Is that a typo or
> are you trying to go somewhere else?
>
> Bill

> > wrend   btfsc   eecon1,wr     ;wait for WR bit to clear
> >          bra     wrend2

Sorry, that was my fault. I cut it from something I'm working on and
foolishly tidied it up. The original label was indeed wrend2. If I'd
taken the other EEPROM routine we'd be sweet

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2004\06\15@193621 by andrew n1yew

picon face
oh, and the code simulates perfectly in MPLAB.... I wonder if its the chips
that I got or if its the silicon..

--
andrew

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2004\06\16@091228 by andrew n1yew

picon face
I called uC yesterday around 6 (gotta love TZ differences) and I got a demo
they tested that works on the f628. They said that they had no complaints of
problems with the EEs.. The demo seems to work fine... Hrmm, so its probably
my code =| .. What I found curious in their demo was that they didnt wait
for any flags to signal write completion(!).. They tested it on a 4mhz
crystal..
--
andrew

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics

2004\06\16@102342 by Jan-Erik Soderholm

face picon face
andrew n1yew wrote :

> What I found curious in their demo was that
> they didnt wait for any flags to signal write completion(!)..

That's probably just fine, *IF* they test the flag
*before* writing. Didn't they do that either ?

Jan-Erik.

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics

2004\06\16@112319 by Bob Axtell

face picon face
Jan-Erik Soderholm wrote:
> andrew n1yew wrote :
>
>
>>What I found curious in their demo was that
>>they didnt wait for any flags to signal write completion(!)..

That's because they didn't care on exit... They check it BEFORE they
enter the routine.

>
>
> That's probably just fine, *IF* they test the flag
> *before* writing. Didn't they do that either ?
>

Yes, they did.

-------

Jinx asked about my documenting some problems with EEROM data dropping
out. I was called in when the bits started dropping out, so its possible
that the mainline code was causing the bit dropouts, as it was written in C.

The client described odd dropouts, just randomly occuring, days after
being written. No other special circumstances were noted.

I found no good reason, either. The bits seemed to be single changes in
random locations. I fixed it by rewriting the read and write routine as
follows:

1. I kept the data, about 16bytes worth, together with a checksum byte.
I then duplicated that data in 2 other places inside the EEROM unit.

2. When the program needs a byte from EEROM, the entire field is read
including the checksum, and if the checksum is OK, the data in that
field is used, but..

3. If the field seems to have an error, another field, then another,
until the data from the good field is located.

4. If another field besides the first had to be read, the offending
fields are rewritten.

5. Finally, the data is used as needed.

It solved his problem. Chip was a PIC16F648A, if I recall.

--Bob

--

Replier: Most attachments rejected
      --------------
        Bob Axtell
PIC Hardware & Firmware Dev
  http://beam.to/baxtell
      1-520-219-2363

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics

2004\06\16@151043 by hilip Stortz

picon face
it could also easily be a layout problem, which are hard to find even
with a scope sometimes.  too slow a transition because capacitive or
other loading, or noise coupling in signal lines or power supply can all
easily cause maddening semi random problems (if you're lucky they are
consistent problems, much, much easier to trouble shoot).  was this a
software or hardware demo or both?  if it was only software that is
probably the source of the problem, but it could still be something more
subtle and maddening.

andrew n1yew wrote:
{Quote hidden}

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics

2004\06\16@155158 by andrew n1yew

picon face
> >>What I found curious in their demo was that
> >>they didnt wait for any flags to signal write completion(!)..

> That's because they didn't care on exit... They check it BEFORE they
> enter the routine.

> > That's probably just fine, *IF* they test the flag
> > *before* writing. Didn't they do that either ?

> Yes, they did.

Do they? I don't see any checking in this code here:

<skip init code>
main

call ewrite
nop
incf EEDATA
incf EEADR,F
movf EEADR,W
xorlw 0x30  ; compare for stop write
btfsc   STATUS,Z
goto finis
movlw 0x00
goto main
finis
bcf  STATUS,RP0
bsf  PORTB,0  ; LED attached to PORTB,0 will light
goto finis  ; Endless loop - done


ewrite      ; WRITE ROUTINE

bsf  STATUS,RP0  ; BANK 1
bsf  EECON1, WREN ; Enable write
movlw 0x55   ;
movwf EECON2   ; Write 55 ( required )
movlw 0xAA
movwf EECON2   ; Write AA ( required )
bsf  EECON1,WR  ; Set WR bit
retlw 0

I don't see it.. Do you?

--
andrew

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics

2004\06\16@161803 by Bob Axtell

face picon face
You are right, I didn't see any in this code either. But I thought you
guys meant the F628 manual (DS40044A), which states on the top of
right-hand column on page 91: "..At the completion of the write cycle,
the WR bit is cleared in hardware. .....the user can ... poll this bit."

--Bob


andrew n1yew wrote:
{Quote hidden}

--

Replier: Most attachments rejected
      --------------
        Bob Axtell
PIC Hardware & Firmware Dev
  http://beam.to/baxtell
      1-520-219-2363

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics

2004\06\16@162632 by andrew n1yew

picon face
That code was from the guy I spoke to at microchip.. He tested it on a 628
with a 4mhz xtal and it worked.. It worked for me also.. Just now adapting
my code and solving its problems..

--andrew
{Original Message removed}

2004\06\16@184525 by Bob Barr

flavicon
face
On Wed, 16 Jun 2004 13:10:49 -0600, Philip Stortz wrote:

>it could also easily be a layout problem, which are hard to find even
>with a scope sometimes.  too slow a transition because capacitive or
>other loading, or noise coupling in signal lines or power supply can all
>easily cause maddening semi random problems (if you're lucky they are
>consistent problems, much, much easier to trouble shoot).  was this a
>software or hardware demo or both?  if it was only software that is
>probably the source of the problem, but it could still be something more
>subtle and maddening.
>

If I'm not mistaken, this discussion is on the EEPROM within the '628
not an external one. If there's a layout problem, it's on the die and
it's going to be up to Microchip to fix it. :=)


Regards, Bob

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics

2004\06\16@190225 by Jinx

face picon face
> That code was from the guy I spoke to at microchip.. He tested it
> on a 628 with a 4mhz xtal and it worked.. It worked for me also..
>Just now adapting my code and solving its problems..

It's disappointing you're having this trouble. Writing to EEPROM
really isn't that difficult. Set the address/data, do the magic sequence,
wait for the write-complete. Or WR can be polled before entry (same
as checking Busy in an LCD routine can be done at either end of
the process). If you have an application in which you want to spend
the minimum of time in the EEPROM routine then pre-testing is
preferable, as the write could take > 2ms. With WR post-testing,
s/w is held up in a wait loop

Personally, I would not use the code MC gave you with no completion
checking apparent. The code I showed you really does work across
all the PICs I've ever used. I use it a lot when debugging to copy RAM
blocks so they can be read with a PicStartPlus

The MC example does work though, kind of. BUT I did get two 0E,
two 12, and two 1D and it sometimes took 5 seconds to complete
that loop. With WR checking added it's perfect every time and takes
a repeatable < 0.1s

So testing WR is not mandatory, just very very advisable. I'd stick my
neck out and say that the advice and example MC gave you is not
good, especially considering they set the rules

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics

2004\06\16@195111 by andrew n1yew

picon face
From: "Jinx" <KILLspamjoecolquittKILLspamspamCLEAR.NET.NZ>


> It's disappointing you're having this trouble. Writing to EEPROM
> really isn't that difficult. Set the address/data, do the magic sequence,
> wait for the write-complete. Or WR can be polled before entry (same
> as checking Busy in an LCD routine can be done at either end of
> the process). If you have an application in which you want to spend
> the minimum of time in the EEPROM routine then pre-testing is
> preferable, as the write could take > 2ms. With WR post-testing,
> s/w is held up in a wait loop

Indeed, I agree it *is* easy.. I don't know why it was giving me all this
trouble..

> Personally, I would not use the code MC gave you with no completion
> checking apparent. The code I showed you really does work across
> all the PICs I've ever used. I use it a lot when debugging to copy RAM
> blocks so they can be read with a PicStartPlus

Yup, I believe you.. I plugged it into my asm file and it works beautifully.

> The MC example does work though, kind of. BUT I did get two 0E,
> two 12, and two 1D and it sometimes took 5 seconds to complete
> that loop. With WR checking added it's perfect every time and takes
> a repeatable < 0.1s
>
> So testing WR is not mandatory, just very very advisable. I'd stick my
> neck out and say that the advice and example MC gave you is not
> good, especially considering they set the rules

I agree.. it seemed really weird to me that they didn't check...

Yay, now I can continue working on my code.. By the way, this is going into
my free open source clone of Byonic's TinyTrak III.

-andrew

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics

2004\06\17@032910 by Alan B. Pearce

face picon face
>> It's disappointing you're having this trouble. Writing to EEPROM
>> really isn't that difficult. Set the address/data, do the magic sequence,
>> wait for the write-complete. Or WR can be polled before entry (same
...

>Indeed, I agree it *is* easy.. I don't know why it was giving me all this
>trouble..

I have not followed your code, but I get the impression that the write to
eeprom is being terminated in an ungracious way before the hardware has
finished the write operation. You do need to keep the eeadr and eedata
registers stable from the time the magic sequence is done right through to
when the write flag shows the write has completed. I wonder if you happen to
have some banking issues elsewhere in the code which is corrupting the eeadr
or eedata registers before the write is complete. The issues could even be
inside an interrupt routine. Been there myself, not with writing to eeprom,
but finding strange banking issues that corrupt data at most inopportune
moments.

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.

2004\06\17@091236 by DJMurray

flavicon
face
part 0 44 bytes
his is a multi-part message in MIME format.
part 1 2158 bytes content-type:text/plain; charset=Windows-1252; format=flowed (decoded 7bit)

----------------------------
OK, guys!

Don't know who's doing what to whom, but I use EEPROM reads & writes all
the time on the 16F628 and have yet to hit a problem!!

I just grabbed a snippet of code from one of my projects and attached it
to this message.  The last routine is the one actually calling the
EEPROM_Write routine - it is included to show how I set up the
parameters needed for the call.

The actual write routine looks long, but really isn't complicated - just
doing a verified read after the
write to ensure everything went OK.

Email me off-line if it doesn't work for you & we'll discuss it.

Good luck - it really isn't very hard!!
Dennis




Alan B. Pearce wrote:

{Quote hidden}

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.




part 2 3555 bytes content-type:text/plain;
(decoded 7bit)

;
;   The next set of fields define EEPROM Addresses for remembered constants
;
EE_Flag_Reg equ 0x00            ;EEPROM Address for Flag_Reg contents
EE_X_Fraction   equ     0x01            ;EEPROM Start Address for 4-byte calibration
EE_Y_Fraction   equ     0x05            ;EEPROM Start Address for 4-byte calibration
;End of EE_Fractions at 0x08!!!!
;
;   End of EEPROM Addresses
;
       CONSTANT SAVE = 0x7E    ;Base address of data that will go into EEPROM
;
;       Following will point to common Register area between banks
;       Used to hold data written to EEPROM
;
EEDATA_Hold     equ     SAVE    ;Hold area needed by EEPROM Write routine
;
       org 0x2100  ;EEPROM address for programmer
       de 0x00,0x80,0x00,0x00,0x00,0x40,0x00,0x00,0x00   ;initial values stored in EEPROM
;
;

<SNIP>

;*********************************************************************
;
;  EEPROM Subroutines
;-----------------------
;
EEPROM_Read
       bsf     STATUS,RP0                      ;Point to Bank 1
       movwf   EEADR                   ;Save in EE address register
       bsf     EECON1,RD                       ;Set flag for read
       movf    EEDATA,W                ;W reg now contains flag info
       bcf     STATUS,RP0                      ;Point to Bank 0
       Return
;
;-----------------------
;
EEPROM_Write
       bsf     STATUS,RP0              ;Set up in bank 1
       movwf   EEADR                   ;Save in address register
       movf    EEDATA_Hold,w   ;Pick up data
       movwf   EEDATA          ;Place in EEPROM Write Register
;   Now do actual write operation
       bsf     EECON1,WREN             ;Enable WRITE operation
       bcf     INTCON,GIE              ;Disable all interrupts during write
       movlw   0x055
       movwf   EECON2          ;Write 55
       movlw   0xAA
       movwf   EECON2          ;Write AA
       bsf     EECON1,WR               ;Set Write bit
;
;   Wait for WRITE to complete
;
       bcf     STATUS,RP0              ;Go back to Bank 0
X_1_Wait
       btfss   PIR1,EEIF               ;Wait until EE write complete
       goto    X_1_Wait                ;Not yet - wait
       bcf     PIR1,EEIF               ;Clear write complete flag
       bsf     STATUS,RP0              ;Go back to Bank 1
;   OK, now read back what was written
       movf    EEDATA,W                ;Pick up data intended for storage
       bsf     EECON1,RD               ;Start a read
;  Now check to ensure data actually written
;  agrees with intended data (in W reg)
       subwf   EEDATA,w                ;EEDATA contains data actually written
       bcf     STATUS,RP0              ;Go back to Bank 0 (Doesn't affect status settings)
       btfss   STATUS,Z                ;Are they equal?
       goto    EEPROM_Error    ;No!!  ERROR!!
;
;   Yes, they are equal
;
;End_Of_EE_Write
       bcf     EECON1,WREN             ;Disable WRITE operation
       bsf     INTCON,GIE              ;Re-enable all interrupts
       Return
;
;
;************************************************************************
;

<SNIP>

;
;   Now save in EEPROM for future reference
;
       movf    Fraction,w              ;Pick up data
       movwf   EEDATA_Hold             ;Save where EEPROM Write can access
       movlw   EE_X_Fraction           ;Pick up EEPROM Address of Fraction
       call    EEPROM_Write


--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.



2004\06\17@101344 by hilip Stortz

picon face
my mistake, i should pay more attention.

Bob Barr wrote:
-------
> If I'm not mistaken, this discussion is on the EEPROM within the '628
> not an external one. If there's a layout problem, it's on the die and
> it's going to be up to Microchip to fix it. :=)
>
> Regards, Bob
>
> --
> http://www.piclist.com hint: The list server can filter out subtopics
> (like ads or off topics) for you. See http://www.piclist.com/#topics

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.

More... (looser matching)
- Last day of these posts
- In 2004 , 2005 only
- Today
- New search...