Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs

Linker error when merging twi-examples into ble_app_uart

Hello,

as I see, many in DevZone have had a problem like this: we tried to merge twi-functionality into the basic ble_app_uart example. We set proper defines in sdk_config.h, we add missing .c files, and we add include paths, but the linker just complains that it cant see some of the functions like `nrfx_twim_init' or "nrfx_twim_enable". 

In my case, I did the following

  • copied the main.c code from twi_sensor into my main.c
  • added nrf_drv_twi.c, nrfx_twi.c and nrfx_twi_twim.c into the  /nRF_Drivers section of my codebase
  • add the following include paths in the "common" project settings:
    • ../../../../../../integration/nrfx
    • ../../../../../../integration/nrfx/legacy
    • ../../../../../../modules/nrfx
    • ../../../../../../modules/nrfx/drivers/include

    • ../../../../../../modules/nrfx/hal

    • ../../../../../../modules/nrfx/mdk

  • Configured my sdk_config.h so that it matches the one from the twi_scanner and twi_sensor examples (please see the attachment):

and I ended up with the linker errors:

Building ‘MERS_s132’ from solution ‘MERS_s132’ in configuration ‘Debug’

Linking MERS_s132.elf
Output/Debug/Obj/MERS_s132/nrf_drv_twi.o: in function `nrf_drv_twi_init':
undefined reference to `nrfx_twim_init'
Output/Debug/Obj/MERS_s132/MERS_LIS3DH.o: in function `nrf_drv_twi_enable':
undefined reference to `nrfx_twim_enable'
Build failed

I scratched my head a long time about this one. Everything seemed like in those two examples, and like the people in DevZone have suggested.

Finally, after the suggestion of one member here, I deleted all TWI-related defines from TWI_ENABLED on, and the error is gone. But when I flashed my nRF52-DK, something was wrong -  the scanner application returned true for every address probed (but obviously there should be no devices present).

So what sense does it make? What should be used in the end? Why do twi-examples work with legacy defines just fine?

I'm using SDK  v17.1.0 on nRF52-DK, 

Best regards, 

P.

Related