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

  • In the end i found the way to make it work. I will explain in case someone else is in the same situation.

    Basically, I declare the SPI instances and the TWI instance, as you suggested. Then, in my sdk_config.h, I add the following line:

    #ifndef PERIPHERAL_RESOURCE_SHARING_ENABLED
    #define PERIPHERAL_RESOURCE_SHARING_ENABLED 1 //https://devzone.nordicsemi.com/f/nordic-q-a/17035/twi0-and-spi0-time-multiplex
    #endif

    I initialize the SPIs as in the peripherals/spi example. Then, when I want to use them, I do it like this:

    spi0_init();
    spi0_xfer_done = false;
    spi0_tx_buf[0]=0x01;
    spi0_tx_buf[1]=0x8F;
    APP_ERROR_CHECK(nrf_drv_spi_transfer(&spi0, spi0_tx_buf, spi0_length, spi0_rx_buf, spi0_length));
    while (!spi0_xfer_done)
    {
    	__WFE();
    }
    nrf_drv_spi_uninit(&spi0);

    This way, the code compiles and seems to do stuff. I am not getting the expected results, so something may be badly configured, but it is good as a starting point. Basically, I am initializing and uninitializing the peripheral every time I use it because I cannot use TWI0 and SPI0 at the same time since they share the base address. 

    The SPI transaction seems to be executed, but what I receive in spi0_rx_buf is a long number (always the same number), regardless of what I am writing. If I am getting something wrong, please do not hesitate to correct me.

    Best regards,

    Alin O. Dragomir

Related