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

Exact match. Not showing close matches.
PICList Thread
'[PIC:] Function to Write EEPROM'
2004\05\21@103020 by Lucian

flavicon
face
Hi guys,

I have a program who uses EEPROM to store some strings for a menu. Until
some hours ago, the menu didn't work and I was wondering why. I
discovered that the procedure that writes to the EEPROM the strings
received was causing the trouble and if I comment it, all the rest works
fine. I use a 16F877A PIC and the code for the function is as follows:

void eeprom_wr(unsigned char addr, unsigned char value) {

       while(WR)continue;
//    addr &= 0x7F;
       EEADR=addr;
       EEDATA=value;
       EEPGD = 0;
       WREN=1;

       CARRY=0;
       if(GIE)CARRY=1;
       GIE=0;

       EECON2=0x55;
       EECON2=0xAA;

       WR=1;
       WREN=0;
       if(CARRY)
               GIE=1;
       EEIF = 0;
}

Now I cannot imagine the reason for which the function causes the
program to hang or to act abnormally. The EEPGD bit is cleared, so it is
not writing to the flash.
Any suggestions are more than welcomed...

Lucian Copat

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

2004\05\21@103849 by hael Rigby-Jones

picon face
{Quote hidden}

Are you writing several bytes to the eeprom?  This function waits for each
byte to be written before returning, and at 4~5ms per byte, it's possible
that you are getting a watchdog timeout, especialy if the watchdog
pre-scaler is 1:1 which gives an ~18ms timeout.

Regards

Mike




=======================================================================
This e-mail is intended for the person it is addressed to only. The
information contained in it may be confidential and/or protected by
law. If you are not the intended recipient of this message, you must
not make any use of this information, or copy or show it to any
person. Please contact us immediately to tell us that you have
received this e-mail, and return the original to us. Any use,
forwarding, printing or copying of this message is strictly prohibited.
No part of this message can be considered a request for goods or
services.
=======================================================================
Any questions about Bookham's E-Mail service should be directed to
postmasterspamKILLspambookham.com.

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

2004\05\21@104308 by Lucian

flavicon
face
I am writing at least 4 bytes, at maximum 12 bytes, but I don't have the
watchdog timer enabled. After writing, the program act as like the
content of the flash would have been altered, even resets itself. Is
anything else except clearing the bit EEPGD to do to protect the program
memory ?

Lucian


{Original Message removed}

2004\05\21@110548 by Lucian

flavicon
face
I observed now that the problem happens when I write more than one byte
in a burst. If I only write the first letter of each option, it works...
It's strange...should I put a delay after each write ?

Regards,

Lucian


{Original Message removed}

2004\05\21@112649 by Alan B. Pearce
face picon face
>I observed now that the problem happens when I write more than one byte
>in a burst. If I only write the first letter of each option, it works...
>It's strange...should I put a delay after each write ?

Most definitely. In fact if you look at the example code in the data sheet
it tells you to check to see if the eeprom portion is busy writing before
doing the next write - at least this is the case for 16F series, haven't
checked the 18f series, but I am not aware of any technology changes in this
area.

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

2004\05\24@030642 by hael Rigby-Jones

picon face
>-----Original Message-----
>From: Alan B. Pearce [.....A.B.PearceKILLspamspam.....RL.AC.UK]
>Sent: 21 May 2004 16:27
>To: EraseMEPICLISTspam_OUTspamTakeThisOuTMITVMA.MIT.EDU
>Subject: Re: [PIC:] Function to Write EEPROM
>
>
>>I observed now that the problem happens when I write more
>than one byte
>>in a burst. If I only write the first letter of each option, it
>>works... It's strange...should I put a delay after each write ?
>
>Most definitely. In fact if you look at the example code in
>the data sheet it tells you to check to see if the eeprom
>portion is busy writing before doing the next write - at least
>this is the case for 16F series, haven't checked the 18f
>series, but I am not aware of any technology changes in this area.

The function that the OP listed previously waits for the eeprom's busy flag
to clear before attempting a wite, so a delay should not be required.  The
function looks very much like the one used in HiTech PICC, and I have used
this many times to write a string of bytes to the EEPROM with no problem.
If the watchdog is definitely disabled, then I see no reason for this code
sequence to cause problems.

Regards

Mike




=======================================================================
This e-mail is intended for the person it is addressed to only. The
information contained in it may be confidential and/or protected by
law. If you are not the intended recipient of this message, you must
not make any use of this information, or copy or show it to any
person. Please contact us immediately to tell us that you have
received this e-mail, and return the original to us. Any use,
forwarding, printing or copying of this message is strictly prohibited.
No part of this message can be considered a request for goods or
services.
=======================================================================
Any questions about Bookham's E-Mail service should be directed to
postmasterspamspam_OUTbookham.com.

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email @spam@listservKILLspamspammitvma.mit.edu with SET PICList DIGEST in the body

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