SparkFun Qwiic EEPROM (COM-18355)
A simple-to-use I2C library for talking to any EEPROM. It uses the same template system found in the Arduino EEPROM library so you can use the same get() and put() functions.
Various external EEPROMs have various interface specs (overall size, page size, write times, etc). This library works with all types and allows the various settings to be set at runtime. All read and write restrictions associated with pages are taken care of. You can access the external memory as if it was contiguous.
Once the library has been started, the memory type needs to be set, the following is an example for the Qwiic 24xx512 EEPROM:
myMem.setMemoryType(512);
Where 512 is the model (ie, 24LC512). Setting the memory type configures the memory size in bytes, the number of address bytes, and the page size in bytes. The following memory types are valid: 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1025, 2048
- 0 - 24xx00 / ie 24LC00
- 1 - 24xx01 / ie 24LC01B
- 2 - 24xx02 / ie 24LC02B
- 4 - 24xx04 / ie CAT24C04
- 8 - 24xx08 / ie BR24G08
- 16 - 24xx16 / ie 24AA16
- 32 - 24xx32 / ie 24LC32A
- 64 - 24xx64 / ie 24FC64
- 128 - 24xx128 / ie 24LC128
- 256 - 24xx256 / ie 24AA256
- 512 - 24xx512 / ie 24C512C
- 1025 - 24xx1025 / ie 24LC1025
- 2048 - 24xx2048 / ie AT24CM02
For a list of all the EEPROM datasheets, please see this repo. We don't want to store the PDFs in the library repo, otherwise, every user will have to download all the PDFs just to install the library.
Alternatively, the individual settings can be set. If setMemorySizeBytes/setAddressBytes/setPageSizeBytes() are called, they will overwrite any previous settings set by setMemoryType()
.
myMem.setMemorySizeBytes(65536);
myMem.setAddressBytes(2); // Set address bytes and page size after MemorySizeBytes()
myMem.setPageSizeBytes(128);
Set the memory type, or set the memory settings, but not both.
This library is best used with the Qwiic EEPROM.
This library can be installed via the Arduino Library manager. Search for SparkFun External EEPROM.
Want to help? Please do! We are always looking for ways to improve and build out features of this library.
Thanks to:
- Hutch67 for correcting the test for pollForWriteComplete setting
- TylerBird for correcting ambiguous int declaration and adding STM32 support
- quarcko for small EEPROM support (24LC02).
- robsonos adding for nRF52 support.
- RayNieport for adding RP2040 support.
- wolfbert for adding ESP8266 support.
- romain145 for fixing a multi-page write bug.
- wollewald for read/write strings.
- giminotron5 for adding write protect control.
- merlinz01 for adding putChanged() method
- /examples - Example sketches for the library (.ino). Run these from the Arduino IDE.
- /src - Source files for the library (.cpp, .h).
- keywords.txt - Keywords from this library that will be highlighted in the Arduino IDE.
- library.properties - General library properties for the Arduino package manager.
- Installing an Arduino Library Guide - Basic information on how to install an Arduino library.
This product is open source!
Various bits of the code have different licenses applied. Anything SparkFun wrote is beerware; if you see me (or any other SparkFun employee) at the local, and you've found our code helpful, please buy us a round!
Please use, reuse, and modify these files as you see fit. Please maintain attribution to SparkFun Electronics and release anything derivative under the same license.
Distributed as-is; no warranty is given.
- Your friends at SparkFun.