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

Getting I2C/TWI working?

There seems to be 3 different libraries that can be used to access TWI: nrf_drv_twi, twi_hw_master, twi_sw_master. (please correct if i am wrong).

i am using SDK8.1. Which library is the most stable?

Is there any example code i could learn from?

thank you.

Parents
  • twi_hw_master : Driver for TWI master that uses TWI hardware in nRF chip

    twi_sw_master : driver for TWI master that does not use TWI hardware but uses GPIO to bitbang the protocol.

    both of the above are marked as incubated in SDK8.1 and most probably will be depreciated in the future releases. Marking incubated is the way to tell you that support will be stopped for these modules soon.

    nrf_drv_twi: New Driver released in SDK8.1 for TWI hardware module for abstracting the TWI hardware in the chip. This module must be used for new development.

Reply
  • twi_hw_master : Driver for TWI master that uses TWI hardware in nRF chip

    twi_sw_master : driver for TWI master that does not use TWI hardware but uses GPIO to bitbang the protocol.

    both of the above are marked as incubated in SDK8.1 and most probably will be depreciated in the future releases. Marking incubated is the way to tell you that support will be stopped for these modules soon.

    nrf_drv_twi: New Driver released in SDK8.1 for TWI hardware module for abstracting the TWI hardware in the chip. This module must be used for new development.

Children
  • Thank you. Your answer really helps set the context for these libraries. I am used to the terminology "deprecated" so thank you also for clarifying "incubated" . When using Keil 5, does it matter if I use the Pack or Zip version of the SDK? Which is the preferred/safest way? I like the Pack installer because I can just click and all dependencies are taken care of.

  • If you are asking, then my personal opinion is that I would prefer zip. Extract the zip and all the extracted examples work right away. Packs are nice when they work, but they have a lot of dependencies and also many places where it could go wrong. Again it is a personal choice and we recommend you to use zip files. Gives you clear picture of what you are doing. If this has answered your question please accept this answer by clicking ' ✓' near the votes button

  • Again, thank you. I hope this is my last ? for now...and next twi is working. I've gotten the twi example to build/load. What I am not sure of is which gpio pins are being used for SCL and SDA. With twi_master, this is in twi_master_config.h. This include file is not part of the nrf_drv_twi. Rather, there is nrf_drv_config.h. I copied the twi section over and changed to TWIO_ENABLED 1. This means TWIO_CONFIG_SCL 0...but i am not sure where this gets mapped to a gpio pin? (I apologize up front if this is a n00b question).

  • Which example did you make it work/load? there is no example in SDK8.1 that uses nrf_drv_twi

  • Hi,

    #define TWI0_CONFIG_SCL 0
    #define TWI0_CONFIG_SDA 1
    

    These are the pin numbers that get assigned which you can find in nrf_drv_twi.h

    #define NRF_DRV_TWI_DEFAULT_CONFIG(id)                                                \
        {                                                                                 \
            .frequency          = TWI_CONFIG_FREQUENCY(id),                               \
            .scl                = TWI_CONFIG_SCL(id),                                     \
            .sda                = TWI_CONFIG_SDA(id),                                     \
            .interrupt_priority = TWI_CONFIG_IRQ_PRIORITY(id),                            \
        }
    

    note if you want to use two TWI modules , you have to assign different pins to all