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

nRF52840 TWI library error

Hi,

I have included in my code the code from the twi_scanner example as a starting point for using TWI in my board. When compiling, I get the following error:

../../../../../../integration/nrfx/legacy/nrf_drv_twi.h:120:37: error: 'NRF_DRV_TWI_INSTANCE_0' undeclared here (not in a function)

The error happens in the exact same  nrf_drv_twi.h used by the example, and I am not finding any way to understand what is happening. Any help would be appreciated, thank you very mucn.

Best regards,

Alin

  • I am having the exact same problem with SPI, and I suspect it has something to do with sdk_config.h. I have backed up my project and tinkered a little with it, trying to copy and paste the parts that are missing in my sdk_config.h and that are present in the one in the example, but I still get the same result. I tried to use the big generic sdk_config.h from \config\nrf52840\config , and I got different errors, so the solution to this one must have something to do with sdk_config.h yet I cannot figure out what it is.

  • I'm not able to reproduce your exact issue, but it sounds like there is some wrong configuration in your sdk_config.h file. Please make sure you have set the NRFX_TWI/TWIM and TWI_ENABLED configs similar to the example:

  • the issue was in my sdk_config.h. What I did is profit from the fact that this file is written with "ifdefine", and I just copied and pasted one after the other the code from different sdk_config.h files from different examples. That way, I only modified what was missing, and now the TWI is working. I will try to do the same for SPI, hopefully it will work too.

  • I am trying the same approach for SPI, that is, copying from the sdk_config.h file in the SPI example, but i still get the same compilation error.

    ../../../../../../integration/nrfx/legacy/nrf_drv_spi.h:120:37: error: 'NRF_DRV_SPI_INSTANCE_1' undeclared here (not in a function)

    Is there an sdk_config.h file that implements 3 SPI interfaces? I am implementing one right now, and I am having trouble, I don't expect to be able to do it for 3 interfaces this way. Thank you.

  • There is no examples in the SDK implementing 3 SPI instances, but you can easily enable this yourself in the default SPI example:

    In sdk_config.h, set SPI1_ENABLED and SPI2_ENABLED to 1, in main, add two new instances on SPI1 and SPI2, in addition to the existing instance of SPI0:

    static const nrf_drv_spi_t spi0 = NRF_DRV_SPI_INSTANCE(0); /**< SPI instance 0. */
    static const nrf_drv_spi_t spi1 = NRF_DRV_SPI_INSTANCE(1); /**< SPI instance 1. */
    static const nrf_drv_spi_t spi2 = NRF_DRV_SPI_INSTANCE(2); /**< SPI instance 2. */

     

Related