I have been looking for a way to asynchronously write to the EEPROM peripheral from the Atmega328p (aka Arduino UNO). To my surprise, there isn't any library available and the only discussion I found was in avr freaks.
As you may know the EEPROM library from the Arduino SDK uses under the hood the EEPROM API from avr-libc. This API follows the datasheet example and blocks for 3.4 ms per byte.
The library I present here avoids blocking by transferring data to the EEPROM via interrupt and when it's done it notifies the user of this event. I did not add a ring buffer to reduce overhead and its up to the user that the data is not modified while doing a transfer.
Perhaps for sequential programming code and super loops, this is not interesting as you are already wasting CPU cycles with delays and other Arduino SDK blocking functions. However, this could also be useful if you are using event-driven architecture such as the QP framework and want to improve your system performance.
Attached is the library, which is already uploaded to the library registry of Arduino.
I just tested with an Arduino UNO but feel free to test it with any other compatible AVR which uses the same EEPROM registers.
Any feedback is welcomed.
Regards,
Victor
For how long does it block? Blocking is relative - in some sense every machine cycle is blocking, a floating point operation blocks... it's just a matter of how long. Some hard numbers along with your introduction would be nice.
Each write.operation takes 3.4 ms (refer to Table 7-1). If you plan to store lets say 100 bytes it can take around 340 ms.
If you have an application where you need to process other events in the meantime then you are blocked and in the best case scenario you miss soft deadlines
You don't have to wait even for writing, let the "write finish interrupt signal" to load the next byte to write.
With a combination of proper state machine and interrupt, this can be made completely non-blocking except for the cycles involves in basic configuration