Aussie Susan
Advanced Member level 5
Be careful when you write the two values to the EECON2 register to perform the unlocking when you are writing in C. It is better to write this as in-line assembler so that any compiler optimisations or other compiler generated code does not stop these two instructions being executed by the CPU consecutively.
Even better, as you are using the XC8 compiler, use the 'eeprom_write' and 'eeprom_read' library functions (see section 5.5.5.3 in the XC8 User Guide).
In your previous replies, you mention that this works after a minute but now immediately. However your code will always immediately write to then read from the EEPROM and do into an infinite loop. Where does the "after a minute" come in to operation?
Also the first thing you do is to write to the EEPROM so how can you tell that it is not holding the values across a power down?
In short, the code you have presented does not match the symptoms you have described.
Susan
Even better, as you are using the XC8 compiler, use the 'eeprom_write' and 'eeprom_read' library functions (see section 5.5.5.3 in the XC8 User Guide).
In your previous replies, you mention that this works after a minute but now immediately. However your code will always immediately write to then read from the EEPROM and do into an infinite loop. Where does the "after a minute" come in to operation?
Also the first thing you do is to write to the EEPROM so how can you tell that it is not holding the values across a power down?
In short, the code you have presented does not match the symptoms you have described.
Susan