'NRFX_TWIM1_INST_IDX' undeclared here (not in a function); did you mean 'NRFX_TWI0_INST_IDX'?

Hello, sir.

I used to work on twi0 and twi1, but now I'd want to shift both twim0 and twim1. However, I'm getting an error saying that 'NRFX TWIM1 INST IDX' is undeclared here (not in a function); did you mean 'NRFX TWI0 INST IDX'?
I checked the NRFX TWIM1 ENABLED macro in the nrfx spim.h file, and it's disabled in apply old config.h, but it's enabled in the sdk config.h file.
Why is apply old config.h being used instead of sdk config.h? What is the best way to solve this issue?
Please take a look at the sdk config.h file I've sent.

2133.sdk_config.txt


  • /** @brief Macro for creating a TWI master driver instance. */
    #define NRFX_TWIM_INSTANCE(id) \
    { \
    .p_twim = NRFX_CONCAT_2(NRF_TWIM, id), \
    .drv_inst_idx = NRFX_CONCAT_3(NRFX_TWIM, id, _INST_IDX), \ here getting the error
    }

    #ifndef __NRFX_DOXYGEN__
    enum {
    #if NRFX_CHECK(NRFX_TWIM0_ENABLED)
    NRFX_TWIM0_INST_IDX,               // disabled

    #endif
    #if NRFX_CHECK(NRFX_TWIM1_ENABLED)
    NRFX_TWIM1_INST_IDX,
    #endif
    #if NRFX_CHECK(NRFX_TWIM2_ENABLED)
    NRFX_TWIM2_INST_IDX,
    #endif
    #if NRFX_CHECK(NRFX_TWIM3_ENABLED)
    NRFX_TWIM3_INST_IDX,
    #endif
    NRFX_TWIM_ENABLED_COUNT
    };
    #endif

  • Hello mahi,

    This looks like it could be an artifact of the apply_old_config file's behavior - please make sure to remove the legacy define's (TWI_ENABLE) from your sdk_config all together if you intend to use the nrfx drivers. If the peripheral's legacy definitions are present (defined) in the sdk_config file the apply_old_config file will overwrite your nrfx configuration with the legacy configuration.
    I see that TWI_ENABLED is defined in your sdk_config. Please remove this, and see if it resolves your issue.

    Best regards,
    Karl

  • Hello, sir.
    Thank you for your reply. I was able to solve the problem.
    Could you please take a look at this twim code transmit and receive function?
    Here is the code that I am sharing with you, just take a look at it.

    What I've seen tramit happen is that I'm not getting  receive the data.

    hardware is working with different code.

    uint8_t I2C_transfer(uint8_t slave_address,uint8_t reg_address, uint8_t write_data)
    {

    uint8_t ctp_data[2]={0,0};
    uint8_t write_length=2;
    ret_code_t err_code1 = 0;
    ctp_data[0] = reg_address;
    ctp_data[1] = write_data;

    m_xfer_done1 = false;
    const nrfx_twim_xfer_desc_t test = NRFX_TWIM_XFER_DESC_TX(0x38, ctp_data, write_length);
    err_code1 = nrfx_twim_xfer(&i2c, &test, 0);
    APP_ERROR_CHECK(err_code1);

    while(m_xfer_done1 == false)
    {
    NRF_LOG_INFO("loop");
    NRF_LOG_INFO("error %x",err_code1);
    vTaskDelay(5);
    }


    }

    //*************************************************************************************//
    // Function: I2C_receive
    // Description: Write one byte to the spacifed I2C slave address at the specified register address.
    // (8 bit offset only) and write data.
    // No error information is returned.
    //*************************************************************************************//
    uint8_t I2C_receive(uint8_t slave_address,uint8_t reg_address)
    {
    ret_code_t err_code1;
    uint8_t data[5];
    uint8_t rx_data[10];
    data[0]=reg_address;

    //set the flag again so that we can read data from the FT5306 s internal register

    m_xfer_done1 = false;

    //err_code = nrf_drv_twi_tx(&m_twi1,slave_address,data,1, false);
    //APP_ERROR_CHECK(err_code);
    const nrfx_twim_xfer_desc_t test = NRFX_TWIM_XFER_DESC_TX(0x38, data, 1);
    err_code1 = nrfx_twim_xfer(&i2c, &test, 0);
    APP_ERROR_CHECK(err_code1);
    NRF_LOG_INFO("rx tx func %x",err_code1);

    while (m_xfer_done1 == false)
    {
    }

    //set the flag again so that we can read data from the FT5306 s internal register

    m_xfer_done1 =false;
    nrfx_twim_xfer_desc_t xfer = NRFX_TWIM_XFER_DESC_RX(0x38, rx_data, 1);
    err_code1=nrfx_twim_xfer(&i2c, &xfer, 0);
    APP_ERROR_CHECK(err_code1);
    while (m_xfer_done1 == false)
    {
    }
    NRF_LOG_INFO("rx_data %d ",rx_data[0]);

    return rx_data[0];
    }

  • Hello,

    mahi354 said:
    Thank you for your reply. I was able to solve the problem.

    No problem at all, I am happy to help!
    I am glad to hear that it resolved your issue.

    mahi354 said:

    Could you please take a look at this twim code transmit and receive function?
    Here is the code that I am sharing with you, just take a look at it.

    What I've seen tramit happen is that I'm not getting  receive the data.

    For future reference, please always use the Insert -> Code option when sharing code here on DevZone.

    Could you elaborate further on what you mean when you say that you see the transmit happen, but that you are not receiving it? Or do you mean that the I2C_transfer is successful, but not the I2C_receive?
    Are you seeing the data clocked out on the bus using a Logic Analyzer, but there is no answer from the slave device?
    I notice that you are doing a TX and then RX in your receive function, is this intentional? Could you detail exactly what you would like to transfer and receive in the receive function, preferably as mentioned in the slave device's datasheet?

    Best regards,
    Karl

  • Hello, sir.

    Yes, sir, data is being transmitted. I'm setting the flag in twi handler so that we can check that the transfer was successful.
    So I'm trying to read the register data with the I2C receive function next
    In this code, I broadcast the register address I want to read first, then I call the receive function.
    Could you perhaps clarify my doubt about the receiving function just being the correct way to perform what I'm doing?

Related