Jump to content
Sign in to follow this  
Prefekt

Eeprom Problmes

Recommended Posts

Hello,

I'm stored values in the internal EEPROM from a 16F876. After a reset are the values sometime corrupted oder the values are not the same. Somtimes after a reset, the values are ok?

 

Can anybody explain me why and how I can store my values right in the internal EEPROM?

 

Thanks

Volker

Share this post


Link to post
Share on other sites
Hello,

I'm stored values in the internal EEPROM from a 16F876. After a reset are the values sometime corrupted oder the values are not the same. Somtimes after a reset, the values are ok?

 

Can anybody explain me why and how I can store my values right in the internal EEPROM?

 

Thanks

Volker

 

Have you disabled intererupts before writing to EEPROM?

 

Are you remembering to disable EEPROM writes when you have finished writing your data to EEPROM? If you do not do this then it is possible that the PIC is crashing when power is removed (as is typical) and is overwriting the EEPROM.

 

Also before writing to the EEPROM are you checking to see that the EEPROM is not busy from a previous write operation?

Share this post


Link to post
Share on other sites

Hello,

here is my code to work with the eeprom.

 

#include <system.h>

 

//the memory bank 0 should be selected

void write_flash( char addr, char data )

{

//Write flash

eeadr = addr;

eedata = data;

 

set_bit( status, RP0 );

set_bit( eecon1, WREN );

eecon2 = 0x55;

eecon2 = 0xAA;

set_bit( eecon1, WR );

while(eecon1&2);

clear_bit( eecon1, WREN );

clear_bit( status, RP0 );

}

 

char read_flash( char addr )

{

//Read flash

eeadr = addr;

set_bit( eecon1, RD );

asm movf _eedata, W

}

 

With a little test prg it works fine. But if I call the write functions from my Project, the values are not stored in the eeprom. If I debug my project, somtimes the values for paramter of the function was not overgiven!

Do you known the problem.

 

Ragards

Share this post


Link to post
Share on other sites

Prefekt,

 

First, why do you use bankswitchingcode? C2C generates that code for you,

you don't need to switch bank.

 

second, you need to disable global interrupts when writing to the EEPROM.

 

And very important, you need to select EEPROM data instead of

programmemory... : "clear_bit(eecon1,EEPGD);"

 

I use this code to read/write the EEPROM and using C2C compiler (not BoostC!):

 

#include <system.h>

unsigned char read_eeprom(unsigned char addr)
{
  eeadr = addr;                 // low byte
  eeadrh = 0;                   // high byte
  clear_bit(eecon1,EEPGD);      // select eeprom memory
  set_bit(eecon1,RD);           // set read bit
  return(eedata);
}

void write_eeprom(unsigned char addr, unsigned char data)
{
  eeadrh = 0;                  // high byte
  eeadr = addr;                // low byte
  eedath = 0;                  // high byte
  eedata = data;               // low byte
  clear_bit(eecon1,EEPGD);     // select eeprom data memory
  set_bit(eecon1,WREN);        // enable write
  disable_interrupt(GIE);      // disable all interrupts
  eecon2 = 0x55;
  eecon2 = 0xaa;
  set_bit(eecon1,WR);          // write command
  enable_interrupt(GIE);       // enable all interrupts
  while(eecon1&2);             // wait untill writing is ready
  clear_bit(eecon1,WREN);      // disable write
}

Grtz, Teuniz

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