This is a generic class that implements 24CXX I²C EEPROMs.
Header file:
Interface
define a 24CXX device:
HW_24CXX(...) defines a 24CXX device. You must provide:
- the I²C interface the device is connected to;
- the slave address of the device;
- the address size in bytes (1, 2);
- the pagesize in bytes.
Example:
#define EEPROM HW_24CXX( interface, twi0, \
address, 0x50, \
addresssize, 2, \
pagesize, 8 )
The implementation of this device focuses on code size rather than on speed, so it relies on extern C functions. These functions are declared with
HW_DECLARE(...) and defined with
HW_IMPLEMENT(...):
- read multiple bytes from the EEPROM:
uint8_t r ;
address, a,
size, s,
buffer, b );
if (r < s)
error();
- write multiple bytes into the EEPROM:
uint8_t r ;
address, a,
size, s,
buffer, b );
if (r < s)
error();