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

error: 'NRF_DRV_TWI_INSTANCE_0' undeclared here

I'm trying to enable TWI in the eddystone example based on this article but I get the following compilation error:

nrfx/legacy/nrf_drv_twi.h:120:37: error: 'NRF_DRV_TWI_INSTANCE_0' undeclared here (not in a function)
main.c
#include "nrf_drv_twi.h"

#define TWI_INSTANCE_ID 0
static const nrf_drv_twi_t m_twi = NRF_DRV_TWI_INSTANCE(TWI_INSTANCE_ID);

sdk_config.h

//==========================================================
#ifndef NRFX_TWI_ENABLED
#define NRFX_TWI_ENABLED 1
#endif
// <q> NRFX_TWI0_ENABLED  - Enable TWI0 instance
 

#ifndef NRFX_TWI0_ENABLED
#define NRFX_TWI0_ENABLED 1
#endif


#ifndef TWI_ENABLED
#define TWI_ENABLED 1
#endif


// <e> TWI0_ENABLED - Enable TWI0 instance
//==========================================================
#ifndef TWI0_ENABLED
#define TWI0_ENABLED 1
#endif
// <q> TWI0_USE_EASY_DMA  - Use EasyDMA (if present)
 

#ifndef TWI0_USE_EASY_DMA
#define TWI0_USE_EASY_DMA 1
#endif

// </e>

//==========================================================
#ifndef NRFX_TWIM_ENABLED
#define NRFX_TWIM_ENABLED 1
#endif
// <q> NRFX_TWIM0_ENABLED  - Enable TWIM0 instance
 

#ifndef NRFX_TWIM0_ENABLED
#define NRFX_TWIM0_ENABLED 1
#endif

Added nrf_drv_twi.c to the project. 

I can compile the twi_sensor project so the issue must be in the configs.
Should I add anything else into the sdk_config.h to make the TWI work?


  • hi....gos ... hope you can help me.. i couldn't understand the above pic

  • Hi Saral

    I also faced this issue when I move from SDK-11 to SDK-15. Please take a look on examples\peripheral\twi_sensor example, main.c and sdk_config.h file it will help you a lot.

  • Hey rolandvagyok,

    Please let us know what is it you did with sdk_config.h to get it work :o

  • I had this problem as well.

    I solved it by modifying sdk_config.h as follows (find these lines and update the values):

    #define NRFX_TWIM_ENABLED 1
    #define NRFX_TWI_ENABLED 1
    #define TWI_ENABLED 1
    #define TWI0_ENABLED 1
    #define TWI0_USE_EASY_DMA 1

    If you look in SDK 15.2 ...\integration\nrfx\legacy\nrf_drv_twi.h, you will see the following around line 120. In order for NRF_DRV_TWI_INSTANCE_0 to be defined, one of the four #if statements must evaluate to true. In my case it should have been the first one, NRFX_TWIM0_ENABLED.

    /**
     * @brief Macro for creating a TWI master driver instance.
     */
    #define NRF_DRV_TWI_INSTANCE(id)    NRF_DRV_TWI_INSTANCE_(id)
    #define NRF_DRV_TWI_INSTANCE_(id)   NRF_DRV_TWI_INSTANCE_ ## id
    #if NRFX_CHECK(NRFX_TWIM0_ENABLED)
        #define NRF_DRV_TWI_INSTANCE_0 \
            { 0, { .twim = NRFX_TWIM_INSTANCE(0) }, true }
    #elif NRFX_CHECK(NRFX_TWI0_ENABLED)
        #define NRF_DRV_TWI_INSTANCE_0 \
            { 0, { .twi = NRFX_TWI_INSTANCE(0) }, false }
    #endif
    #if NRFX_CHECK(NRFX_TWIM1_ENABLED)
        #define NRF_DRV_TWI_INSTANCE_1 \
            { 1, { .twim = NRFX_TWIM_INSTANCE(1) }, true }
    #elif NRFX_CHECK(NRFX_TWI1_ENABLED)
        #define NRF_DRV_TWI_INSTANCE_1 \
            { 1, { .twi = NRFX_TWI_INSTANCE(1) }, false }
    #endif

    I found the #define NRFX_TWIM0_ENABLED in SDK 15.2 ...\integration\nrfx\legacy\apply_old_config.h

    #define NRFX_TWIM0_ENABLED (TWI0_ENABLED && TWI0_USE_EASY_DMA)

    So, I went into my sdk_config.h and updated those #defines with non-zero values, and voila! Problem solved! Slight smile

  • Hi. I am having the exact same issue, but my config file has all these enabled

    #define NRFX_TWIM_ENABLED 1
    #define NRFX_TWI_ENABLED 1
    #define TWI_ENABLED 1
    #define TWI0_ENABLED 1
    #define TWI0_USE_EASY_DMA 1

    What could be the issue? 

Related