jeddah02 0 Posted November 15, 2006 Report Share Posted November 15, 2006 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 ame result. Is it my code or is it a compiler problem. Quote Link to post Share on other sites
Picxie 0 Posted November 15, 2006 Report Share Posted November 15, 2006 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 ame result. Is it my code or is it a compiler problem. <{POST_SNAPBACK}> Quote Link to post Share on other sites
Dave 0 Posted November 15, 2006 Report Share Posted November 15, 2006 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 Quote Link to post Share on other sites
jeddah02 0 Posted November 15, 2006 Author Report Share Posted November 15, 2006 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??? Quote Link to post Share on other sites
Picxie 0 Posted November 16, 2006 Report Share Posted November 16, 2006 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??? <{POST_SNAPBACK}> Quote Link to post Share on other sites
jeddah02 0 Posted November 16, 2006 Author Report Share Posted November 16, 2006 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 .... Quote Link to post Share on other sites
sdujolo 0 Posted November 16, 2006 Report Share Posted November 16, 2006 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 .... <{POST_SNAPBACK}> 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; } Quote Link to post Share on other sites
jeddah02 0 Posted November 16, 2006 Author Report Share Posted November 16, 2006 Hi, Thanks for the reply. I've tried this code, without the eecon1.EEPGD bit as the PIC16 and PIC12 parts do not have this bit, but it still fails to read so I think it must be a bug. (The code is the same if this bit is ommited). Thanks Quote Link to post Share on other sites
Dave 0 Posted November 17, 2006 Report Share Posted November 17, 2006 Have a look here for the resolution of this problem Quote Link to post Share on other sites
Recommended Posts
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.