Adding I2C-TWI EEPROM access, to existing SPI access

We do have an eeprom accessed over the SPI, and works well.

Need to add an option to access also the I2C eeprom.

Adding to the project nrf_drv_twi,c, nrfx_twi.c, nrfx_twim.c - do I need to use both nrfx_twi.c and nrfx_twim.c?

During compilation somehow defines are not picking up from the sdk_config.h

After adding defines from sdk_config.c directly into modules it compiles, but linker combines interrupts of the SPI/TWI, creating multiple defined objects with SPI/TWI in the interrupt service name.

According to the instances, looks, if I use SPI0, I cannot use TWI0, only TWI1.
Could those peripherals selected dynamically, to use SPI0 and TWI0 one at a time?

  • Most helpful would be a sample application for the Segger studio initializing SPI0 and TWIM1. 
    I am concerned about the twi includes not picking up the defines.

  • Hi

    The SPI and TWI do indeed share instances, so you have to use another TWI instance than SPI instance. I don't think we have any specific examples using both, but we have separate SPI examples and TWI examples. It should be sufficient to move the TWI init function + driver and library files into your existing project and make sure you use a different TWI instance. Depending on what functions you want to use from the nrfx TWI drivers, you choose if you want just the nrfx_twi.c or the nrfx_twim.c (or both).

    Best regards,

    Simon

Related