Jump to content

Recommended Posts

I have been developing an application that requires reading a small table from EEPROM on a 16F876 and writing it back to another area of EEPROM. I was using the library functions in eeprom.pic.lib.

Here is the loop that I use :

 

for (z = 1;z <= 8; z++){

y = eeprom_read(temp_orig);

eeprom_write(temp_start,y);

temp_orig += 1;

temp_start += 1;

}

 

With this version I was getting rubish written to the new location. It appeared to be a timing problem and ended up putting in a delay of 15ms just after the call to write. The problem was solved but still seemed as it should not really exist.

 

I looked at the c file that can be downloaded from boostc.lika.be which I assume to be what was used to build the library. The write function seems to follow the microchip app sheet. The problem is that they use :

 

while (test_bit(eecon1, WR)){}; // wait for write to finish

 

at the start of the write function. This is great if you writing a number of bytes but not if you will be reading from another section of EEPROM to get the byte you want to write such as in the above loop. When eeprom_write() returns the writing process is not finished and the eeprom_read() returns garbish.

 

I first tried replacing my 15ms delay with the "while" statement above. The problem was solved.

 

In the end I modified the sample eeprom.c to put another "while" statement towards the end of the eeprom_write() function. Sort of give protection from both ends of the routine. I did new library build which I now use.

 

All is working.

 

This was used in a a small (8 element) database routine for one wire device 8 byte serial numbers with the possibility of removing an element and re-writing the database.

 

Jim

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...
×
×
  • Create New...