EEPROM driver reusable in different platforms. Supports all I2C speed modes.
- NUCLEO-L552ZE-Q
- NUCLEO-H745ZI-Q
- NUCLEO-U575ZI-Q
eeprom_initialize
: initializes theeeprom_t
instance and adds it in theeeprom_t eeprom_interface
array.eeprom_deinitialize
: deinitializes theeeprom_t
instance.eeprom_read
: reads the data from the eeprom starting from a given address and saves it in the specified buffer. The amount of data to be sent must be specified.eeprom_available
: checks wether the eeprom is free or not.eeprom_wait_sync
: puts the eeprom in timeout.eeprom_write
: writes the data contained in a specified buffer on the eeprom starting from a given address. The amount of data to be sent must be specified.eeprom_clear_all
: writes 0x00 in the whole EEPROM.
-
Set the I2C peripheral in the .ioc file
-
Include the header file
drv_eeprom.h
-
Define an
eeprom_t
handler and initialize/assign properly the structure:instance.handler
: I2C handler of choice.instance.mx_init
: I2C initializing function generated by the configuration tool.instance.dev_addr
: address of the EEPROM.instance.pg_sz
: Page size in bytes.instance.mem_sz
: EEPROM memory size.mem_addr_sz
: Number of bytes of the address
-
Use the function:
eeprom_initialize
: to initialize the EEPROM.eeprom_read
: to read data from the EEPROM.eeprom_write
: to write data on the EEPROM.
This example uses the NUCLEO-L552ZE-Q with the X-NUCLEO-EEPRMA2 board extension.
eeprom_t eeprom_u1 = {
.mx_init = MX_I2C1_Init,
.handler = &hi2c1,
.pg_sz = 16,
.dev_addr = 0xA8,
.mem_addr_sz = 2,
.mem_sz = 2024
};
eeprom_initialize(&eeprom_u1)
memmove(eeprom_read_buffer, rw_buffer, 20);
eeprom_write(&eeprom_u1, 0x000A, eeprom_read_buffer, 20);
memset(eeprom_read_buffer,0, 100);
eeprom_read(&eeprom_u1, 0x0000, eeprom_read_buffer, 20);