Jump to content
Sign in to follow this  
jeddah02

Eeprom Read Fail

Recommended Posts

Bug description:

The eecon1.RD bit does not get set when trying to read from the eeprom memory on 16F and 12F parts.

 

 

Steps to reproduce:

 

the following code was used as a standalone quick test to reproduce the problem

 

#include <system.h>

//#pragma DATA 0x2007, 0x30C4

 

char read;

char i;

 

char eeprom1_read(char address);

void main()

{

while(1){

for(i = 0; i = 20; i++)

read = eeprom1_read(i);

}

}

 

char eeprom1_read(char address)

{

 

eeadr = address;

set_bit(eecon1,RD);

return eedata;

 

}

//------------------------------------------

Expected behaviour:

the eeprom should be read starting at 0 ending at 20 ad infinitum. Can be watched using the simulator.

 

 

IDE version: 6.55

Compiler: Compiler (BoostC )

Compiler version: 6.55

Target device: PIC12F684 and PIC16F648A

 

Fails to read eeprom on every occassion, eeadr register fails to incriment/decriment, and eecon1.RD fails to be set.

Share this post


Link to post
Share on other sites

jeddah02,

 

Bug description:

The eecon1.RD bit does not get set when trying to read from the eeprom memory on 16F and 12F parts.

Is this a problem on the actual device, or just a problem with the simulator?

 

Regards

Dave

Share this post


Link to post
Share on other sites

jeddah02,

As far as I can tell it fails to read eeprom on the actual device so the simulator is probably giving the correct result.

So what is the bug in then?

 

Regards

Dave

Share this post


Link to post
Share on other sites

As i said, its not reading eeprom If I,m asking to read an eeprom location and the program does not read it, then the program crashes The data is written ok but what good is that if you cant read it back later!

:(

Share this post


Link to post
Share on other sites

As i said, its not reading eeprom If I,m asking to read an eeprom location and the program does not read it, then the program crashes The data is written ok but what good is that if you cant read it back later!

:(

Share this post


Link to post
Share on other sites
As i said, its not reading eeprom  If I,m asking  to read an eeprom location and the compiler does not set the eecon1.RD  then no read takes place and the program crashes. I can't say why the read bit is not set as the correct instructions were given. The data is written ok but what good is that if you cant read it back later!

:(

Share this post


Link to post
Share on other sites

jeddah02,

 

The following code works under the SourceBoost simulator with target device PIC16F648A.

 

It uses your code (which works), and also the supplied EEPROM library which also works.

 

I think your problem was your for loop counter, see if you can spot the difference :(

 

 

#include <system.h>
#include <eeprom.h>

// initialise eeprom
#pragma DATA _EEPROM, 12, 34, 56, 78

char read;
char i;

char eeprom1_read(char address);
void main()
{
    while(1)
    {
        for(i = 0; i < 20; i++)
        {
            read = eeprom1_read(i);
            read = eeprom_read( i );
        }
    }
}

char eeprom1_read(char address)
{
    eeadr = address;
    set_bit(eecon1,RD);
    return eedata;

}

 

Regards

Dave

Share this post


Link to post
Share on other sites

Hi Dave,

Yep, I spotted it and wrote some code to flash an led if eeprom was read correctly and Ive tested it on my hardware. The problem is with the simulator after all. It never shows the eecon1.RD bit being set, so when I was debugging I assumed my problem was that the device was not actually being read and I was suffering data loss, which was the symptom I had. I should have realised it was next to impossible for the set_bit() function not to work and not set the required bit. The whole compiler would have folded....

 

:(

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...