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

TWI or TWIM, example

Hi,

I'm new to Nordic Semi chips (nrf52840) and need to use TWI as a master to connect to two sensors. But I'm a bit confused about the different drivers: TWI and TWIM. As far as I understand does the TWI driver not use easyDMA while the TWIM does? Is that the only difference?

I also could not find an example which uses TWIM, they all seem to use TWI? Could you please point me to a good example? 

Thanks!

Roger

Parents
  • Hi Roger,

    I'm new to Nordic Semi chips (nrf52840) and need to use TWI as a master to connect to two sensors. But I'm a bit confused about the different drivers: TWI and TWIM. As far as I understand does the TWI driver not use easyDMA while the TWIM does? Is that the only difference?

    The TWIM peripheral uses DMA, and the TWI peripheral does not. That is not the only difference, but it is the most significant. There are different nrfx drivers for TWI and TWIM, but if you use the legacy API, then you have the same API for both, and use TWI0_USE_EASY_DMA (for instance 0) or TWI1_USE_EASY_DMA (for instance 1) in sdk_config.h to select which peripheral you will use. This will, in turn, decide which of the underlying nrfx driver is used.

    I also could not find an example which uses TWIM, they all seem to use TWI? Could you please point me to a good example? 

    The SDK example uses the legacy driver API, so to switch from TWI to TWIM you just need to set TWI0_USE_EASY_DMA to 1. Several of the SDK example has this set to 1 by default, and therefore use TWIM unless you change it.

    Einar

  • Hi Einar thanks for your answer. If I set TWI0_USE_EASY_DMA to 1 is it then still a legacy project? Then for me is not quite clear why I should use legacy drivers for a new project? How can I setup a new project just using TWIM without the legacy parts, it seems there is no example so I have do do it from scratch? If so: Why you don't change the examples to the latest API? Thanks again, Roger

Reply
  • Hi Einar thanks for your answer. If I set TWI0_USE_EASY_DMA to 1 is it then still a legacy project? Then for me is not quite clear why I should use legacy drivers for a new project? How can I setup a new project just using TWIM without the legacy parts, it seems there is no example so I have do do it from scratch? If so: Why you don't change the examples to the latest API? Thanks again, Roger

Children
  • Hi,

    Neuer said:
    If I set TWI0_USE_EASY_DMA to 1 is it then still a legacy project?

    You will use the legacy API in both cases, but the actual implementation will be nrfx in both cases. This particular configuration macro determines if you use the TWI peripheral (without DMA) or the TWIM peripheral (with DMA).

    Neuer said:
    Then for me is not quite clear why I should use legacy drivers for a new project?

    The "conversion" between API's are handled by the preprocessor, so there will not be any difference in the actual code regardless of which API you use. My personal preference is for keeping the legacy API if you have done anything. If not, then it is up to you, but there are a few pitfalls, so please make sure to follow the migration guide in detail if you want to use the nrfx API directly.

    Neuer said:
    Why you don't change the examples to the latest API?

    It has not been changed in the SDK because it has not been prioritized. Given limited resources that sort of makes sense, since it does not make a real difference.

Related