This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Compiler error: unknown type name 'nrf_drv_twi_t' for nRF5340 , the IDE SDK 15.0

we develop the TWI I2C interface,  already setting the Enable TWIM driver in the Project Setting. but.

the code :

const nrf_drv_twi_t m_twi_instance = NRF_DRV_TWI_INSTANCE(0);
const nrf_drv_twi_config_t twi_mpu_config = {
.scl = MPU_TWI_SCL_PIN,
.sda = MPU_TWI_SDA_PIN,
.frequency = NRF_TWI_FREQ_400K,
.interrupt_priority = APP_IRQ_PRIORITY_HIGHEST,
.clear_bus_init = false
};

the error is :

2> Compiling ‘main.c’
2> ../src/main.c:143:8: error: unknown type name 'nrf_drv_twi_t'

Setting is :

How we can enable the nrf_drv_twi legacy driver in this project ? 

  • Hi, Robert!

    The nRF legacy drivers are not available in the nRF Connect SDK, but you can use the nrfx drivers. They are available under modules\hal\nordic\nrfx\drivers\include, with the TWI header files being nrfx_twim.h and nrfx_twi.h.

    Best regards,
    Carl Richard

  • Hi Richard.

    Thanks for your response. We try to use the nrfx m the i2c pin is P1.02 and P1.03 (nRF5340DK). Compiler work, but running is fail about the nrfx_twim_init , the code is : 

    const nrfx_twim_t m_twi_instance = NRFX_TWIM_INSTANCE(1);

    void i2c_nrfx_test(void)
    {
    nrfx_err_t err_code;

    const nrfx_twim_config_t twimConfig = {
    .scl = 34,
    .sda = 35,
    .frequency = NRF_TWIM_FREQ_400K,
    .interrupt_priority = 1,
    .hold_bus_uninit = true
    };
    printk("test1");
    err_code = nrfx_twim_init(&m_twi_instance, &twimConfig, twim_handler, NULL);
    //APP_ERROR_CHECK(err_code);
    if (err_code != NRFX_SUCCESS) {
    printk("Failed to initialize device %d",err_code-NRFX_SUCCESS);
    //return -EBUSY;
    }

    .......

    the output is 

    test1

    Failed to initialize device 5 

    have any i mistake...

  • Hello again!

    The code runs fine here. Are you doing anything else in the application? Note that only one instance of a peripheral with the same number can be active at the same time (i.e. UART1 and I2C1 can't be active simultaneously).

    Best regards,
    Carl Richard

  • Hi Richard.

    Thanks your information. i use the zephry api to binding the I2C_1 device, that's working , but use the nrfx api , still fail .   have any setting we have to check it. 

    the zephry code is :

    #define TWI_DEVICE_NAME "I2C_1"

    i2c_dev = device_get_binding(TWI_DEVICE_NAME);
    if (!i2c_dev) {
      printk("device_get_binding I2C_1 (=%s) failed\n", TWI_DEVICE_NAME);
    }

    the result i2c_dev not NULL ,  can work and control the i2c interface.

  • Hi!

    Are you using the Zephyr API and nRFx drivers in the same application? If you bind I2C_1 using Zephyr and then try to enable TWI1 using nRFx it will fail. You should only need to enable one of them.

    Best regards,
    Carl Richard

Related