PDA

View Full Version : Write EEPROM with Interrupts



Zapman
- 20th April 2023, 19:43
I am getting closer to the testing stage of my project but have one question. In the PBP manual it says that if interrupts are used the following define should be used.

DEFINE WRITE_INT 1

further in the code I have a sequence of writes, four in a row like below,

write Degrees_up, word vdegrees_up
write Degrees_10, word vdegrees_10
write Degrees_20, word vdegrees_20
write Degrees_30, word vdegrees_30
.
.
rest of code

If I am reading the manual correctly, the define statement will mask and unmask the interrupts while the write is occurring. Is this correct?

Thanks for any clarification you can provide.

Zapman

mpgmike
- 21st April 2023, 00:45
First, you don't mention which PIC you're using. Newer ones have a NVM Interrupt that can be used to set an interrupt when done writing to the EEPROM. Older ones need the GIE disabled when writing to the EEPROM. This might be a start.

Zapman
- 21st April 2023, 19:20
Sorry I didn't mention the chip. It is a PIC18F45K80. I was asking because the PBP manual talks about needing to mask the interrupts during EEPROM writes. I am using DT's interrupt handling software and have modified it for the K80. My real question is do I use the Define statement to handle masking the interrupts during EEPROM writes?

Thanks

Ioannis
- 21st April 2023, 21:28
If in your design, an interrupt can occur during EEPROM write, then use GIE bit to disable temporary all interrupts. After WRITE enable GIE again. Thats all.

Ioannis

tumbleweed
- 22nd April 2023, 11:21
If you use 'DEFINE WRITE_INT 1' then the library code will disable interrupts around the unlock and setting EECON1.WR to initiate the write operation, but unlike the sequence shown in most datasheets it will reenable them before the write operation is completed.

DaveP
- 22nd April 2023, 13:28
That"s right, DEFINE WRITE_INT 1 is all that you need. I have used it for about 7 years with out any problems. I used to use Ioannis way at first and it worked as well.

Zapman
- 22nd April 2023, 16:20
That"s right, DEFINE WRITE_INT 1 is all that you need. I have used it for about 7 years with out any problems. I used to use Ioannis way at first and it worked as well.

Thanks for the answer! I sometimes find small snippets or statements in the manual that leave me wondering about the actual functioning. In this case it was the DEFINE WRITE_INT 1. I found it mentioned but didn't see the explanation about how it worked. Thanks again to all. I can get back to programming now... maybe after another cup of coffee!