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

NRF/NRFX TWI manager configurations & NRFX_TWI0_INST_IDX undeclared

Cheers!

I've been working to enable TWI0 for our current project, but I've been getting stuck on this compile error:

../SDK/modules/nrfx/drivers/include/nrfx_twi.h:73:35: error: 'NRFX_TWI0_INST_IDX' undeclared here (not in a function); did you mean 'NRFX_TWIM0_INST_IDX'?
     .drv_inst_idx = NRFX_CONCAT_3(NRFX_TWI, id, _INST_IDX), \

I've updated my sdk_config to enable NRFX_TWI0, and I've attempted both to enable the legacy TWI/TWI0 as well as remove them from the sdk_config completely (per a suggestion for SPI posted here devzone.nordicsemi.com/.../142936 )

Additionally I've tossed in an if else in my main.c that'll tell me at compile time if TWI0 is enabled or not (Doesn't compile with this on, but I'll uncomment it and compile to check what it can see) and so far, regardless of what I do, I end up with NRFX_TWI0_ENABLED FALSE

SDK Config settings got NRFX TWI

And if/else check that tells me True or False after verifying NRFX_TWI0_ENABLE

  • Have you tried to set TWI0_ENABLED and TWI_ENABLED to 1 (not NRFX_TWI..), I think that will solve your problem.

    The reason for this is that NRFX_TWI0_ENABLED is defined as follows (in the file apply_old_config.h):

    #undef NRFX_TWI0_ENABLED
    #define NRFX_TWI0_ENABLED   (TWI0_ENABLED && !TWI0_USE_EASY_DMA)

    Best regards, Simon

  • I have the same issue. I'm trying to use the "nrfx_twim.h" library and functions in the ble_app_hrs example. I am getting the same error. I have NRFX_TWIM_ENABLED = 1, NRFX_TWIM0_ENABLED = 1, THen I set, TWI_ENABLED = 1 and TWI0_ENABLED = 1. I can't figure out why if I am using the new libraries and functions I should need the apply_old_config.h file. I also can't figure out why that section of code in nrfx_twim.h is failing. I added debuggers in main.c and the output confirms the asserted definitions above are correct. What am I missing? BTW, I am trying to compile with GCC. I switched the functions from  nrf_drv to nrfx_ because it won't compile in GCC, although it did compile in Keil with nrf_drv_

  • Update: I guess something else in the sdk_config file is forcing apply_old_config, so I have to go back to nrf_drv_ functions--but I am back to getting "undefined reference to 'nrfx_twi_tx" and "nrfx_twi_rx".  In sdk_config.h iI have only set TWI_ENABLED  and  NRFX_TWI_ENABLED  since that was in the logical statement and it still failed. Then I put in a print line to see if TWI_PRESENT was defined and it was. So I'm confused as to why this redefinition in  is not executing and the nrfx_twi_tx function is not defined. Way down in nrfx_twi.h where this function is defined I ran the same NRFX_CHECK error check and it passed. I can muck with nrfx_twi.h and get errors so I know it is being called by nrf_drv_twi.h and TWI_PRESENT is defined. So why are they functions being defined?  

    Looks like my nrfx_twi.c function is not being compiled--I can muck with it but it doesn't do anything. I need to figure out how to modify the makefile to link it.

    Update: Solved. For some reason the Keil project was able to find and link nrfx_twi.c and nrf_drv_twi.c but I had to manually add them to the makefile for gcc.

  • UPDATE
    I get TRUE finally when I do the opposite, actually. I took another shot at purging every non-nrfx mention of TWI from the sdk_config and now it gives me both true and compiles as intended! I must have left something behind last I tried this. THANK YA'LL for the help :D !!
     

    Gave it a shot with
    TWI0_ENABLED 1
    TWI0_USE_EASY_DMA 1
    with the nrfx_twi definitions both present and completely striped from the sdk_config. Seems like it simply overwrites if it's already present/defined, but at this point I'm trying everything. Neither method fixes this unfortunately.

    so nrfx_twi.c is definitely being brought in and compiled; Added  a few tests in here as well to see what's going on...
     

    #if NRFX_CHECK(NRFX_TWI_ENABLED)
        #error "NRFX_TWI_ENABLED TRUE"
    #else
        #error "NRFX_TWI_ENABLED FALSE"
    #endif


    With the above I'm getting NRFX_TWI_ENABLED FALSE on compile.
    Also tried massaging that into


    #if NRFX_TWI_ENABLED==0
        #error "NRFX_TWI_ENABLED FALSE"
    #else
        #error "NRFX_TWI_ENABLED TRUE"
    #endif


    And still, FALSE.

    The result's the same
    No matter what I change, add, or remove, NRFX_TWI_ENABLED is 0

  • Glad to hear that you finally made it work. Please ask if you enter any more problems.

    Cheers, Simon

Related