Searching \ for '[PIC]: Clear EEPROM routine, why does it stall?' 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: 'Clear EEPROM routine, why does it stall?'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]: Clear EEPROM routine, why does it stall?'
2002\02\16@195631 by Nick Masluk

picon face
Below is the code I am using on a PIC16F627 to clear
the EEPROM from address 0x000 to 0x07E (0x07F stores a
variable that is not to be deleted).  Sometimes it
works, sometimes it doesn't.  When the code doesn't
work, the loop is still running, it just doesn't exit
it, because no WDT reset ever occurs.  The PIC is
running 4MHz INTRC oscillator I/O function, and all
interrupts are disabled.

;start
       bsf     STATUS, RP0
       movlw   0x0FF
       movwf   EEDATA
       clrf    EEADR
nxtadr  bsf     EECON1, WREN
       movlw   0x055
       movwf   EECON2
       movlw   0x0AA
       movwf   EECON2
       bsf     EECON1, WR
       bcf     EECON1, WREN
       clrwdt
       incf    EEADR, F
       movlw   0x07F
       xorwf   EEADR, W
       btfss   STATUS, Z
       goto    nxtadr
       bcf     STATUS, RP0
;end

Thanks,

--Nick

__________________________________________________
Do You Yahoo!?
Yahoo! Sports - Coverage of the 2002 Olympic Games
http://sports.yahoo.com

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


2002\02\16@205906 by Bob Barr

flavicon
face
On Sat, 16 Feb 2002 16:54:13 -0800, Nick Masluk wrote:

>Below is the code I am using on a PIC16F627 to clear
>the EEPROM from address 0x000 to 0x07E (0x07F stores a
>variable that is not to be deleted).  Sometimes it
>works, sometimes it doesn't.  When the code doesn't
>work, the loop is still running, it just doesn't exit
>it, because no WDT reset ever occurs.  The PIC is
>running 4MHz INTRC oscillator I/O function, and all
>interrupts are disabled.

Check datasheet DS40300B, section 13.2
I think the problem is that you aren't checkimg bit EEIF in register
PIR1 to ensure that the previous write is complete before you write
again. Note that this bit must be cleared by your code before you use
it again to check for completion of the next write.

Regards, Bob

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


2002\02\16@235346 by Nick Masluk

picon face
Nope, that doesn't seem to be it.  I added the
following code to the end of all places where the
EEPROM is written to, and it always ends up in a WDT
time-out.

       btfss   PIR1, EEIF
       goto    $-1
       bcf     PIR1, EEIF

I think this may not have been working because it is
an interrupt flag, and I have all interrupts disabled,
therefor the flag may be inactive.  And if clearing
the EEIF flag was such an important part in properly
writing to the EEPROM I would like to think that more
mention to it would have been made than in that small
section of 13.2.

--Nick


--- Bob Barr <spam_OUTbbarrTakeThisOuTspamCALIFORNIA.COM> wrote:
{Quote hidden}

__________________________________________________
Do You Yahoo!?
Yahoo! Sports - Coverage of the 2002 Olympic Games
http://sports.yahoo.com

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


2002\02\17@091844 by Olin Lathrop

face picon face
> Nope, that doesn't seem to be it.  I added the
> following code to the end of all places where the
> EEPROM is written to, and it always ends up in a WDT
> time-out.

EEPROM writes can be quite slow.  Is it possible that the watchdog triggers
before the write is complete?  If so, you could kick the dog in the wait
loop.

>         btfss   PIR1, EEIF
>         goto    $-1
>         bcf     PIR1, EEIF
>
> I think this may not have been working because it is
> an interrupt flag, and I have all interrupts disabled,
> therefor the flag may be inactive.

Interrupt flags get set whether interrupts are disabled or not, so this
method is perfectly fine when interrupts are off.

> And if clearing
> the EEIF flag was such an important part in properly
> writing to the EEPROM I would like to think that more
> mention to it would have been made than in that small
> section of 13.2.

I think they documented this very well.  You don't really want the same
information in too many places because it would make the manual too tedius
to read.  The last two sentences of section 13.4, "Writing to the EEPROM
data memory", near the top of the second column on page 93 of DS40300B read
"The user can either enable this interrupt or poll this bit.  The EEIF bit
in the PIR1 register must be cleared by software".  I can't think of a
better place to put this, nor do I find it ambiguous.


********************************************************************
Olin Lathrop, embedded systems consultant in Littleton Massachusetts
(978) 742-9014, .....olinKILLspamspam@spam@embedinc.com, http://www.embedinc.com

--
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


2002\02\17@132848 by Bob Barr

flavicon
face
On Sat, 16 Feb 2002 20:52:25 -0800, Nick Masluk wrote:

>Nope, that doesn't seem to be it.  I added the
>following code to the end of all places where the
>EEPROM is written to, and it always ends up in a WDT
>time-out.
>
>        btfss   PIR1, EEIF
>        goto    $-1
>        bcf     PIR1, EEIF
>
>I think this may not have been working because it is
>an interrupt flag, and I have all interrupts disabled,
>therefor the flag may be inactive.

That appears to be the correct code sequence. Are you sure that you're
in the right bank when it's executed. It's really easy to be in the
wrong bank and not know it. (The errors in examples 13-1 and 13-3
don't help.)

Interrupt flag bits still work regardless of the interrupt enable
state. They just don't generate the interrupt when they're disabled
(or when GIE or PEIE is clear). Figure 14-16 shows this pretty well.

If you would be willing to email your code off-list, I can run it on a
breadboard I've got and try to duplicate your results.

>And if clearing
>the EEIF flag was such an important part in properly
>writing to the EEPROM I would like to think that more
>mention to it would have been made than in that small
>section of 13.2.
>

Nothing ever surprises me about Microchip documentation anymore. :=)
At least they've got it in there somewhere.


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


2002\02\17@134404 by Dwayne Reid

flavicon
face
Try adding a 'clrwdt' as shown below:

At 08:52 PM 2/16/02 -0800, Nick Masluk wrote:
>Nope, that doesn't seem to be it.  I added the
>following code to the end of all places where the
>EEPROM is written to, and it always ends up in a WDT
>time-out.
>
>TestEEfin1
>         clrwdt                   ;tickle dog
>         btfss   PIR1, EEIF       ;write finished
>           goto  TestEEfin1       ;nope
>         bcf     PIR1, EEIF

You have to clear the WDT while you are waiting for the write to
finish.  If you replicate the above code in multiple locations, be sure to
change the digit at the end of label so that each instance is unique.

One other thing: the location of where you clear the interrupt flag may be
a bit dicey: I'd prefer to clear the flag just before starting the write,
not after it is finished as you have done above.

dwayne


Dwayne Reid   <dwaynerspamKILLspamplanet.eon.net>
Trinity Electronics Systems Ltd    Edmonton, AB, CANADA
(780) 489-3199 voice          (780) 487-6397 fax

Celebrating 18 years of Engineering Innovation (1984 - 2002)
 .-.   .-.   .-.   .-.   .-.   .-.   .-.   .-.   .-.   .-
    `-'   `-'   `-'   `-'   `-'   `-'   `-'   `-'   `-'
Do NOT send unsolicited commercial email to this email address.
This message neither grants consent to receive unsolicited
commercial email nor is intended to solicit commercial email.

--
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


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