Jump to content

Recommended Posts

Hi,

I'm having a problem when tring to read eeprom on 12F and 16F devices. I can write to the eeprom ok but the eecon1 register bits do not change on the simulator, or on a real device. The subroutine I've used is

 

unsigned char eeprom12_read(unsigned char address)

{

set_bit(status,RP0);

eeadr = address;

set_bit(eecon1,RD);

clear_bit(status,RP0);

return eedata;

}

 

i've tried the microchip assemply code routine from the 16F648A/12F683 manuals with the s :rolleyes: ame result. Is it my code or is it a compiler problem.

Link to post
Share on other sites

you are clearing rp0 before returning so when you try to return eedata you are returning the contents of a file in bank 0.

 

 

 

Hi,

I'm having a problem when tring to read eeprom on 12F and 16F devices. I can write to the eeprom ok but the eecon1 register bits do not change on the simulator, or on a real device. The subroutine I've used is

 

unsigned char eeprom12_read(unsigned char address)

{

set_bit(status,RP0);

eeadr = address;

set_bit(eecon1,RD);

clear_bit(status,RP0);

return eedata;

}

 

i've tried the microchip assemply code routine from the 16F648A/12F683 manuals with the s :rolleyes: ame result. Is it my code or is it a compiler problem.

Link to post
Share on other sites

Jeddah,

 

Avoid setting bank selection bits, the linker adds appropriate banks select in automatically. Adding them yourself will cause problems as it affects linkers bank selection tracking.

 

Regards

Dave

Link to post
Share on other sites

Are you doing a write before the read. If so it is possible that the write may still be in progress, in which case the read will not happen.

 

Your function should check to see if the WR bit is set and wait till it clears before attempting the read.

 

Hi,

I've removed the status address bits from the code but its made no difference, the eecon1 register read bit does not get set and the return value is  therefore 0. It seems such an 'easy' bit of code to write... Any other suggestions I could try???

:(

Link to post
Share on other sites

Hi,

Thanks for the reply.

 

There is no write to eeprom instruction before the read, on startup the program is set to read the eeprom for data stored before a processor reset or power outage. So the usual processor setup functions are performed and eeprom is then read. Initially, on the first startup there is nothing in to read so I manually inserted some data but to no avail. I have tried the eeprom read function as a 'standalone' test outside of this program but it still fails to read eeprom. Its really got me going ....

:(

Link to post
Share on other sites
Hi,

Thanks for the reply.

 

There is no write to eeprom instruction before the read, on startup the program is set to read the eeprom for data stored before a processor reset or power outage. So the usual processor setup functions are performed and eeprom is then read. Initially, on the first startup there is nothing in to read so I manually inserted some data but to no avail. I have tried the eeprom read function as a 'standalone' test outside of this program but it still fails to read eeprom. Its really got me going ....

:(

 

Hello I use this code from Lieven Hollevoet http://boostc.lika.be I have tested it on 16f876A and 18f4620.

 

/Jörgen

 

 

char eeprom_read(char address){

   // Load address
   eeadr = address;

// Point to EEPROM memory
eecon1.EEPGD = 0;

// 18F devices also need the CFGS bit to be cleared
#ifdef CFGS
eecon1.CFGS = 0;
#endif

// Read, data is available in eedata the next cycle.
eecon1.RD = 1;

// Return value
return eedata;

}

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