Interfacing external EEPROM using I2C drivers on nrf52840 in Zephyr NCS v2.5.0

Hi. I am working on a project and I need to interface a EEPROM to store some data. I tried using I2C drivers from the ncs but it appears that the APIs support only 8 bit addresses as shown below.

Write API:

/**
 * @brief Write multiple bytes to an internal address of an I2C device.
 *
 * This is equivalent to:
 *
 *     i2c_burst_write(spec->bus, spec->addr, start_addr, buf, num_bytes);
 *
 * @param spec I2C specification from devicetree.
 * @param start_addr Internal address to which the data is being written.
 * @param buf Memory pool from which the data is transferred.
 * @param num_bytes Number of bytes being written.
 *
 * @return a value from i2c_burst_write()
 */
static inline int i2c_burst_write_dt(const struct i2c_dt_spec *spec,
				     uint8_t start_addr,
				     const uint8_t *buf,
				     uint32_t num_bytes);

Read API:

/**
 * @brief Read multiple bytes from an internal address of an I2C device.
 *
 * This is equivalent to:
 *
 *     i2c_burst_read(spec->bus, spec->addr, start_addr, buf, num_bytes);
 *
 * @param spec I2C specification from devicetree.
 * @param start_addr Internal address from which the data is being read.
 * @param buf Memory pool that stores the retrieved data.
 * @param num_bytes Number of bytes to read.
 *
 * @return a value from i2c_burst_read()
 */
static inline int i2c_burst_read_dt(const struct i2c_dt_spec *spec,
				    uint8_t start_addr,
				    uint8_t *buf,
				    uint32_t num_bytes);

So, is there any other alternative for this which I can use to access the EEPROM as 8 bits are not enough to access all the addresses. This driver is more suitable for sensors I believe.

Parents
  • Hi Sahil

    These functions are primarily intended for sensors or configuration registers, yes, not for accessing EEPROM devices. 

    If you use the more generic i2c_write(..), i2c_write_dt(..), i2c_read(..) or i2c_read_dt(..) functions you can format the data payload exactly as you wish, and you should be able to use an address size matching that of your connected EEPROM. 

    If you need to do a TX -> RX transaction using repeated start you can use the i2c_transfer(..) or i2c_transfer_dt(..) functions. 

    Another alternative is to check for a native driver for your EEPROM device in Zephyr. If one exists you can interface your device directly using one of the higher level flash API's, rather than interfacing it directly through the I2C driver. 

    Best regards
    Torbjørn

Reply Children
Related