Searching \ for '[PIC]:16F873 writing to flash problem' 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=flash
Search entire site for: '16F873 writing to flash problem'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]:16F873 writing to flash problem'
2000\09\16@043735 by Damien Kee

flavicon
picon face
just wondering if anyone could help.

I'm using a 16F873 as a data logger, and am storing the data in
flash.  Yes I know that I should really put it into serial EEPROM, but it
is for a Uni project, so space and cost are an issue.  I'm having a
problem though, writing to flash.

I write several(5) chars to sucessive flash program space, but then when
I try and read them back, I get the last character that I wrote, 5 times.

was wondering if there is something obvious in the notes that I have
missed, and/or if anyone has any good links to example code which does
this sort of stuff, which I could have a look at.

cheers
damo


Damien Kee
3rd Year Electrical Engineering
University of Queensland
spam_OUTs369472TakeThisOuTspamstudent.uq.edu.au

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


2000\09\16@085546 by Dale Botkin

flavicon
face
Sounds like you have a counter not incrementing, either on write (most
likely) or on read.  Maybe you could post that section of code and have
folks take a look.

Dale

On Sat, 16 Sep 2000, Damien Kee wrote:

{Quote hidden}

---
The most exciting phrase to hear in science, the one that heralds new
discoveries, is not "Eureka!" (I found it!) but "That's funny ..."
               -- Isaac Asimov

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


2000\09\16@120548 by Olin Lathrop

flavicon
face
> I write several(5) chars to sucessive flash program space, but then when
> I try and read them back, I get the last character that I wrote, 5 times.

This sounds like it might be more of a reading than a writing problem.
Anything's possible of course, but it seems a bit unlikely that your write
routine would mess up by filling a region of memory with the same value.
That would require multiple writes, which is something you should be able to
easily check with a scope.  However, suppose your read routine was messed up
where it just ends up getting back whatever is in some data holding
register, which is whatever value was last written regardless of where it
was written to.

I don't know the specifics of your memory, so take this for what it's worth.


*****************************************************************
Olin Lathrop, embedded systems consultant in Devens Massachusetts
(978) 772-3129, olinspamKILLspamcognivis.com, http://www.cognivis.com

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


2000\09\17@062719 by Damien Kee

flavicon
picon face
ok, here are the bits of code relevant.

It's all in c.

In the interrupt handler:
{
               write_flash2(1865, 'A');
               write_flash2(1866, 'B');
               write_flash2(1867, 'C');
               write_flash2(1868, 'D');
               write_flash2(1869, 'E');
               write_flash2(1870, 'F');

               a = read_flash2(1865);
               b = read_flash2(1866);
               c = read_flash2(1867);
               d = read_flash2(1868);
               e = read_flash2(1869);
               f = read_flash2(1870);

               send_char(a);
               send_char(b);
               send_char(c);
               send_char(d);
               send_char(e);
               send_char(f);
}

send_char just sends the value through RS232 to hyperterminal.

the actual functions are as below:
void write_flash2( int addr, char data )
{
       EEADRH = 0x00;
       EEADR = 0x00;
       EEDATA = 0x00;
       EEDATH = 0x00;
       //Write flash
       EEADRH = addr / 256;
       EEADR = addr % 256;
       EEDATA = data;

       set_bit( EECON1, EEPGD);
       set_bit( EECON1, WREN );
       EECON2 = 0x55;
       EECON2 = 0xAA;
       set_bit( EECON1, WR );
       asm nop;
       asm nop;
       clear_bit( EECON1, WREN );
}

char read_flash2(int addr ){
       EEADRH = 0x00;
       EEADR = 0x00;
       EEDATA = 0x00;
       EEDATH = 0x00;
       //Read flash
       EEADRH = addr / 256;
       EEADR = addr % 256;
       set_bit( EECON1, EEPGD);
       set_bit( EECON1, RD );
       asm nop;
       asm nop;
       data_rd = EEDATA;
       send_char(EEDATA);
       return data_rd;
}

I'm doing the mod and divide functions, because I'd like to keep the
destination address as 1 integer.  If there is a better way, I love to
know.

thanks again.

cheers
damo




Damien Kee
3rd Year Electrical Engineering
University of Queensland
.....s369472KILLspamspam.....student.uq.edu.au

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
use EraseMElistservspam_OUTspamTakeThisOuTmitvma.mit.edu?body=SET%20PICList%20DIGEST


2000\09\17@113523 by Byron A Jeff

face picon face
Damien,

It takes time to write to a flash/eeprom memory. From a brief glance at the
code below it doesn't look like you're allowing for the write to complete
before continuing to the next write.

According to the data sheet (which doesn't seem to list a timing parameter
for a flash write) a write is complete when the EEIF flag in the interrupt
register is set. So in your code in the write_flash2 you need to replace
the two nops with a while loop that waits for the EEIF flag to become set.

Note that your code must reset that flag. It doesn't happen automatically.

BAJ
{Quote hidden}

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
use KILLspamlistservKILLspamspammitvma.mit.edu?body=SET%20PICList%20DIGEST


2000\09\17@142734 by Dale Botkin

flavicon
face
On Sun, 17 Sep 2000, Damien Kee wrote:

> ok, here are the bits of code relevant.
>
> It's all in c.

Which C compiler?

{Quote hidden}

Looks OK to me so far...

> send_char just sends the value through RS232 to hyperterminal.
>
> the actual functions are as below:
> void write_flash2( int addr, char data )
                    ^^^^^^^^^
Umm, shouldn't this be long instead of int?  I know at least with CCS and
CC5X you need to use long or int16 if you're going to pass values greater
than 255.

{Quote hidden}

Dale
---
The most exciting phrase to hear in science, the one that heralds new
discoveries, is not "Eureka!" (I found it!) but "That's funny ..."
               -- Isaac Asimov

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
use TakeThisOuTlistservEraseMEspamspam_OUTmitvma.mit.edu?body=SET%20PICList%20DIGEST


2000\09\18@044627 by Damien Kee

flavicon
picon face
Ok, now I'm getting desperate.

I've posted the code at student.uq.edu.au/~s369472/pic/flash1.c

I'm using the C2C++ compiler.

From the code you can see that I write 5 chars to five incrementing
address spaces, then I read back the 5 chars and send them to a hyper
terminal.  Only when they are read, they are all the same.

I've analysed the asm file generated, and it follows the Microchip
datasheet.

I'm really at a loss now as to what to do, and have spent about 2 days
straight trying to solve it.  It is incredably annoying when I have
managed to write all the code necessary for the rest of the project,
teaching myself as I go, in about 5 days, and then to be
stuck on this final hurdle.

thanks to everyone so far for their help,

cheers
damo


Damien Kee
3rd Year Electrical Engineering
University of Queensland
RemoveMEs369472spamTakeThisOuTstudent.uq.edu.au

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


2000\09\18@051811 by Michael Rigby-Jones

flavicon
face
{Quote hidden}

The following function contains some code that I suspect was put in for
debugging :


char read_flash2(long addr ){
       EEADRH = 0x00;
       EEADR = 0x00;
       EEDATA = 0x00;
       EEDATH = 0x00;
       EEADRH = addr / 256;
       EEADR = addr % 256;

       EEADRH = 0x00 ;  You are setting the read address to a constant
here.
       EEADR = 0xFF ;

       set_bit( EECON1, EEPGD);
       set_bit( EECON1, RD );
       asm nop;
       asm nop;
       delay_ms(10);
       data_rd = EEDATA;
       return data_rd;
}

I don't have the 16F877 datasheet to hand, but I suspect there may also be
some timming issues in your flash_write2 function. IIRC you have to poll a
status bit to find out when the flash has finiched being written to.

Cheers

Mike

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


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