Unable to get I2C driver based on example "twi_master_using_nrf_twi_mngr" to work

I am using this SDK version 17.1.0 as I am using ESB in this project.  So far I have gotten ESB, SPI, and UART communications working.  SPI and UART are both using easy DMA, and I was trying to get easy DMA I2C working with this project.  I am using the Segger Embedded Studio toolchain version 7.32a. I am including my sdk_config.h file and my i2cDrv.c that right now just tries to initialize my !2C bus. I am getting the following error. Nothing I am doing seems to be working.  I am also attaching the snippet that shows the pertinent files that are included in my project.

04820.sdk_config.h

/******************************************************************************
 * @copyright
 * Copyright (c) 2026 NeuroGenesis Diagnostics Inc.
 *
 * This software is proprietary and confidential.
 ******************************************************************************
 * @file i2cDrv.c
 *****************************************************************************/

#include "i2cDrv.h"
#include "sdk_config.h"
#include "nrf.h"
#include "sdk_common.h"
//#include "nrf_drv_twi.h"
#include "nrf_twi_mngr.h"


 #define TWI_INSTANCE_ID      0          // TWIM0
#define TWI_QUEUE_LENGTH     20  
#define I2C_SCL_PIN          26
#define I2C_SDA_PIN          27

#define NRF_TWI_MNGR_OP_WRITE(addr) ((addr) << 1)
#define NRF_TWI_MNGR_OP_READ(addr)  (((addr) << 1) | 0x01)

// Create I2C manager instance
NRF_TWI_MNGR_DEF(m_twi_mngr, TWI_QUEUE_LENGTH, TWI_INSTANCE_ID);

void twi_init(void)
{
    nrf_drv_twi_config_t twi_config = {
        .scl                = I2C_SCL_PIN,
        .sda                = I2C_SDA_PIN,
        .frequency          = NRF_TWI_FREQ_400K,   
        .interrupt_priority = APP_IRQ_PRIORITY_LOW,
        .clear_bus_init     = false,
        .hold_bus_uninit    = false
    };

    ret_code_t err_code = nrf_twi_mngr_init(&m_twi_mngr, &twi_config);
    APP_ERROR_CHECK(err_code);
}

Any ideas what I am doing wrong?  If more information is needed just let me know what you need.  Thanks

Parents
  • Hi

    The issue seems to be that you have enabled both the SPI0 and TWI0 is enabled. These use the same instance, which will cause conflicts like this. On the nRF52840 you have up to 4 SPIM instances and 2 TWI instances, but TWI0 and TWI1 uses the same instantation as SPI0 and SPI1, so if you use both TWIs you need to use SPIM2 and SPIM3 for SPI if you require two.

    Best regards,

    Simon

Reply
  • Hi

    The issue seems to be that you have enabled both the SPI0 and TWI0 is enabled. These use the same instance, which will cause conflicts like this. On the nRF52840 you have up to 4 SPIM instances and 2 TWI instances, but TWI0 and TWI1 uses the same instantation as SPI0 and SPI1, so if you use both TWIs you need to use SPIM2 and SPIM3 for SPI if you require two.

    Best regards,

    Simon

Children
Related