Including drivers in my project

Development Kit: NRF52840

IDE: Segger Embedded Studios

I'm trying to use the nrf_drv_twi driver in my project. I've included the .c file in my nFR_Drivers folder. My base project is the uart_pca10056 example and I'm referencing the twi_sensor example for using TWI. When I build the project I get the error on my call to NRF_DRV_TWI_INSTANCE:

"NRF_DRV_TWI_INSTANCE_0 undeclared here (not in a function) did you mean 'NRF_DRV_TWI_INSTANCE_'?"I

I've read some discussions that I need to enable something in the sdk_config.h file but when I go to do that, I notice the file does not contain the nrf_drv_twi defines to do so.

I've tried copying the defines from the twi_sensor example into my sdk_config.h and that still does not solve the problem.

  • Hello,

    Could you confirm that you have added the path to the header file into your Project Options -> Common Configuration -> Preprocessor -> User Included Directories? Please also confirm that you have added the required source files to your project navigator.

    I've read some discussions that I need to enable something in the sdk_config.h file but when I go to do that, I notice the file does not contain the nrf_drv_twi defines to do so.

    I've tried copying the defines from the twi_sensor example into my sdk_config.h and that still does not solve the problem.

    Yes, you will need to add the NRFX_TWI_ENABLED define to your sdk_config, and remove the TWI_ENABLED define.
    If the TWI_ENABLED define is present it will overwrite your nrfx_twi defines.

    You will also need to enable the specific TWI instance you intend to use.
    Could you share your sdk_config with me so that I may take a look?

    Best regards,
    Karl

  • Hi,

    My User Include Directory is set to "Inherits" and when I click the [...] to Set User Include Directories, a text editor appears with only a single "." in it. What is the syntax for adding directories? Do I need to add "nrf_drv_twi.h" to this?

    I will attach a screenshot of the nRF_Drivers folder in my Project Navigator to show which source files I have.

    I will also attach my sdk_config.h. It currently does not have any defines for NRFX_TWI_ENABLED. Am I able to type these in manually? I've noticed the others seem to be auto generated.

    Thanks,

    Jason

    8424.sdk_config.h

  • Hello Jason,

    JasonPierpont said:
    My User Include Directory is set to "Inherits" and when I click the [...] to Set User Include Directories, a text editor appears with only a single "." in it. What is the syntax for adding directories?

    This likely means that you are looking for the project options for the release or debug configuration. You should be looking at the common configuration since this applies to both of the two others.

    JasonPierpont said:
    I will also attach my sdk_config.h. It currently does not have any defines for NRFX_TWI_ENABLED. Am I able to type these in manually? I've noticed the others seem to be auto generated.

    Yes, you may add these yourself. I recommend going into the twi example you are trying to merge, and get the required sdk_config.h configurations from there. I also recommend that you only include the nrfx_twim configuration into your project, since as mentioned if the legacy TWI_ENABLED is defined in sdk_config.h it will overwrite your nrfx_twi configuration.
    Please also make sure to enable the specific TWIM instance you intend on using in the sdk_config.h along with enabling the peripheral as a whole with the NRFX_TWIM_ENABLED define.

    Best regards,
    Karl

  • I've updated my sdk_config.h with the NRFX_TWI_ENABLED defines. (Error is still occurring)

    4617.sdk_config.h

    I was looking at the Common Configuration. I'll attach a screenshot of what I see.

    Thanks,

    Jason

  • Hello again, Jason

    You will need to go to the project options (right click on the project title in the project navigator), not to the options of the particular I2CHandler.c file which you are currently looking in.

    JasonPierpont said:
    I've updated my sdk_config.h with the NRFX_TWI_ENABLED defines.

    Great! This looks correct, so now we just need to make sure that the user included paths match up.
    Are you intentionally using the TWI peripheral, or do you intend to use it with easyDMA (TWIM)?
    Just for good measure, could you confirm that you are using the TWI0 instance in your application as well?

    Best regards,
    Karl

Related