 |
 |
| View previous topic :: View next topic |
| Author |
Message |
PICNick
Joined: 23 Dec 2025 Posts: 1 Location: United Kingdom
|
| #DEVICE WRITE_EEPROM=ASYNC Problem |
Posted: Tue Dec 23, 2025 7:48 am |
|
|
Good Afternoon,
This is my first time posting a question on this forum, so I apologise in advance if I break any rules.
I am currently programming a PIC18F57Q84 with a clock speed of 32MHz and using version 5.115 of the CCS compiler. I am having some trouble with the use of #device WRITE_EEPROM=ASYNC.
In isolation, I have found that #device WRITE_EEPROM=ASYNC works very well. I am using a timer interrupt which, when activated writes 1 byte to eeprom using write_eeprom() every 16ms until a total of 14 bytes have been written. The time taken for each pass through this interrupt is 5us compared with 10ms when the line #device WRITE_EEPROM=ASYNC is not included. I am not writing to eeprom from anywhere within the main program cycle. and I have verified that the write has been successful. So far so good.
Also within my program I have set aside a block of program memory to store some calibration and configuration data. This is done from within the main program cycle and not an interrupt. This also works well when the line #device WRITE_EEPROM=ASYNC is not included, so again, so far all good.
However when I include #device WRITE_EEPROM=ASYNC I am finding that my program locks up on the call to write_program_memory(). It remains frozen for 8 seconds before being restarted by the WDT. There are no lockups without #device WRITE_EEPROM=ASYNC, and everything works perfectly together, other than the writes to eeprom are too slow.
The writes to program memory and eeprom are both very infrequent, and I can confirm that they are not happening at the same time. Interrupts are disabled when the function write_program_memory() is called.
I can find very little information on #device WRITE_EEPROM=ASYNC, other than the warning not to write to eeprom from within and outside of an ISR.
I have tried commenting out all calls to write_eeprom() and compiling with only the functions to write_program_memory() but the code still freezes when it hits this function.
I could free up some space in eeprom for the calibration data so that I no longer need to call write program_memory() but I would rather not do this, especially as I will also be including a bootloader at some point.
Can anyone here provide any clues on what might be happening, or advise me on any workarounds.
Many Thanks,
Nick. |
|
 |
Ttelmah
Joined: 11 Mar 2010 Posts: 20009
|
|
Posted: Tue Dec 23, 2025 8:53 am |
|
|
The problem is you are thinking of these as two separate systems. They
are not. The NVM module handles both. Flash memory and EEPROM are
very similar, ir is just the the EEPROM is built to support single byte
writes, and has much better write life. Both use the same control logic in
the chip.
Read section 10 in the data sheet.
The async operation relies on setting up the pointers for the write and
then letting this complete while the code is still running. Trying to setup
the same registers to perform a write to the program flash while this is
happening, is just not going to work.....
 |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|