| View previous topic :: View next topic | 
	
	
		| Author | Message | 
	
		| cformer 
 
 
 Joined: 18 Sep 2012
 Posts: 2
 
 
 
			    
 
 | 
			
				| internal EEPROM read/write and Code Protection CPD WRTD |  
				|  Posted: Tue Sep 18, 2012 12:22 pm |   |  
				| 
 |  
				| I'm trying to use the internal data EEPROM to store a serial number. 
 I use the write_eeprom() and read_eeprom() commands to read and write bytes and it works fine.
 
 However, when I clear the CPD and WRTD configuration bits (0=write protection enabled), the program cannot write or read as before.
 
 According to the Microchip datasheet  ( PIC18F86K22_39960d.pdf ) this should still work though:
 
 "Data EEPROM memory has its own code-protect bits in
 the Configuration Words. External read and write
 operations are disabled if code protection is enabled.
 The microcontroller itself can both read and write to the
 internal data EEPROM, regardless of the state of the
 code-protect Configuration bit."
 
 Any idea anyone?
 |  | 
	
		|  | 
	
		| PCM programmer 
 
 
 Joined: 06 Sep 2003
 Posts: 21708
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Tue Sep 18, 2012 12:36 pm |   |  
				| 
 |  
				| Your quote is referring to the CPD config bit.   But you are also clearing (ie, enabling) the WRTD bit.   The 18F86K22 data sheet says that WRTD
 prevents the PIC from writing to its internal data eeprom:
 http://ww1.microchip.com/downloads/en/DeviceDoc/39960d.pdf
 
  	  | Quote: |  	  | 28.6.2 DATA EEPROM CODE PROTECTION
 
 The entire data EEPROM is protected from external
 reads and writes by two bits: CPD and WRTD. CPD
 inhibits external reads and writes of data EEPROM.
 WRTD inhibits internal and external writes to data
 EEPROM. The CPU can always read data EEPROM
 under normal operation, regardless of the protection bit
 settings.
 | 
 |  | 
	
		|  | 
	
		| cformer 
 
 
 Joined: 18 Sep 2012
 Posts: 2
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Wed Sep 19, 2012 7:51 am |   |  
				| 
 |  
				| Thank you very much PCM programmer! 
 That fixed it. I hadn't spotted the other paragraph you quoted, and the one I was referring to was not really clear (to me anyway, proven by my misinterpretation).
 |  | 
	
		|  | 
	
		|  |