Refactored Arduino library from JChristensen to STM32 LL(Low-Layer) C library.
- Predefined commonly used EEPROM chip types for easier configuration.
- Fast read and write operations
- Auto memory paging resolving
- No HAL dependencies
How to add CPM to the project, check the link
CPMAddPackage( NAME EEPROM GITHUB_REPOSITORY ximtech/EEPROM GIT_TAG origin/main)
- Start project with STM32CubeMX:
- Select: Project Manager -> Advanced Settings -> I2C -> LL
- Generate Code
- Add sources to project:
add_subdirectory(${STM32_CORE_SOURCE_DIR}/I2C/Polling) # add I2C to project include_directories(${EEPROM_DIRECTORY}) # source directories file(GLOB_RECURSE SOURCES ${EEPROM_SOURCES}) # source files
- Then Build -> Clean -> Rebuild Project
Data write and read from EEPROM
#include "EEPROM_I2C.h" #define EEPROM_I2C_ADDRESS 0xA0 #define EEPROM_VALUE_ADDRESS 0 #define VALUE_TO_SAVE 55 int main() { EEPROM_I2C eeprom = initByTypeEEPROM(I2C1, AT24C04, EEPROM_I2C_ADDRESS); I2CStatus status = beginEEPROM(eeprom); if (status != I2C_OK) { return -1; // failed to start, check status for more info } EEPROMStatus eepromStatus = writeByteEEPROM(eeprom, EEPROM_VALUE_ADDRESS, VALUE_TO_SAVE); uint8_t value = readByteEEPROM(eeprom, EEPROM_VALUE_ADDRESS); printf("%d\n", value); }