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

Hardware TWI/I2C Example

The latest TWI example I can find is from 4 SDK revisions ago and uses old libraries. Is there a sample using the nrf_drv_twi library that is recommended for current development?

Parents
  • Hi

    I have made a simple example using the latest TWI driver in SDK 9. It is very basic;

    1. It sets up and configure a TWI instance.
    2. Transmits dummy bytes to addresses 0x00 to 0x7F and listens for a response from other TWI devices on the bus.
    3. Lights a LED if a device is found.

    I have used this example for a while myself just to get me started on a new TWI project. It is simple, but very handy just to see if you have everything connected and set up correctly.

    Test examples for SDK 0.9.2, 10.0.0, and 11.0.0: twi-find-devices-on-bus.

    twi_simple_SDK9.0.0_v2.zip

    EDIT: The folder path to your example .uvprojx file should look like this: "your_SDK9_folder\examples\peripheral\twi_simple_SDK9.0.0_v2\pca10028\arm5_no_packs\twi_simple_SDK9.0.0_v2.uvprojx". The example is meant to be used with the SDK folder structure in the .zip file here. It is not intended for use with the pack installer.

    EDIT 2: Updated example: twi_simple_SDK9.0.0_v3.zip

    EDIT 3: Response to the questions and comments below regarding build errors:

    @NewToNordic is right in his answer below. The latest pack driver and library versions are v3.1.0 with e.g. new TWI drivers that are not compatible with the older examples. This is how I solved it:

    • Choose "fixed" from the Selection drop down list.
    • Choose version 3.0.1.

    image description

    • If you get an error complaining about "nrf_drv_config_validation.h": No such file or directory, then just comment out the line in nrf_drv_config.h.
    • Then finally enable TWI 1 in nrf_drv_config.h by writing #define TWI1_ENABLED 1.

    This worked for me with the 2nd version example in my initial answer and my nRF51 DK kit.

Reply
  • Hi

    I have made a simple example using the latest TWI driver in SDK 9. It is very basic;

    1. It sets up and configure a TWI instance.
    2. Transmits dummy bytes to addresses 0x00 to 0x7F and listens for a response from other TWI devices on the bus.
    3. Lights a LED if a device is found.

    I have used this example for a while myself just to get me started on a new TWI project. It is simple, but very handy just to see if you have everything connected and set up correctly.

    Test examples for SDK 0.9.2, 10.0.0, and 11.0.0: twi-find-devices-on-bus.

    twi_simple_SDK9.0.0_v2.zip

    EDIT: The folder path to your example .uvprojx file should look like this: "your_SDK9_folder\examples\peripheral\twi_simple_SDK9.0.0_v2\pca10028\arm5_no_packs\twi_simple_SDK9.0.0_v2.uvprojx". The example is meant to be used with the SDK folder structure in the .zip file here. It is not intended for use with the pack installer.

    EDIT 2: Updated example: twi_simple_SDK9.0.0_v3.zip

    EDIT 3: Response to the questions and comments below regarding build errors:

    @NewToNordic is right in his answer below. The latest pack driver and library versions are v3.1.0 with e.g. new TWI drivers that are not compatible with the older examples. This is how I solved it:

    • Choose "fixed" from the Selection drop down list.
    • Choose version 3.0.1.

    image description

    • If you get an error complaining about "nrf_drv_config_validation.h": No such file or directory, then just comment out the line in nrf_drv_config.h.
    • Then finally enable TWI 1 in nrf_drv_config.h by writing #define TWI1_ENABLED 1.

    This worked for me with the 2nd version example in my initial answer and my nRF51 DK kit.

Children
Related