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

TWIS instances

Hi,

I have a situation where I have to create 4 TWIS instances on nRF52832.

sdk_config.h only shows 2 TWIS instances.

// <q> TWIS0_ENABLED  - Enable TWIS0 instance
 

#ifndef TWIS0_ENABLED
#define TWIS0_ENABLED 0
#endif

// <q> TWIS1_ENABLED  - Enable TWIS1 instance
 

#ifndef TWIS1_ENABLED
#define TWIS1_ENABLED 1
#endif

Is it ok if I add other instances (TWIS2_ENABLED and TWIS3_ENABLED) in sdk_config myself (haven't tried it yet)

If not, how can I access 4 TWIS devices if I only create 1 instance of TWIS?

  • Hi Anita

    In order to communicate to an I2C slave the nRF52 device needs to be in master mode. 

    In other words you should use a TWIM instance, not a TWIS instance. 

    A single TWIM instance should be enough to communicate with 4 slaves, as long as the total capacitance on the bus is not too high (in general the more slaves you have the more capacitance you get). Most likely this won't be an issue, but if you start to see communication issues when adding more slaves then it is usually caused by excessive bus capacitance. I would suggest adding a single slave at a time and make sure it all runs nicely (if you connect a scope to the bus you can see if the signalling looks OK). 
    If capacitance issues do occur there are some ways to handle it, such as adding stronger pull up resistors on the bus (lower resistance), setting the nRF52 pins in high drive mode, and reducing the I2C clock frequency. 

    When using the twi master driver you have to provide the address for every transaction, allowing you to select which sensor to talk to. 

    For an example, have a look at the API documentation for the nrf_drv_twi_tx(..) function, and note the address parameter. 

    Best regards
    Torbjørn

  • as long as the total capacitance on the bus is not too high

    Indeed.

    Note that this is a standard I2C thing - not specific to Nordic.

    I2C is designed for short connections between chips on the same PCB - so, as says, capacitance should not normally be a problem.

    But a common case where problems do often arise is when prototyping and attaching dev kits together with long wires. Solderless breadboards are particularly notorious for having high capacitance.

    if you connect a scope to the bus you can see if the signalling looks OK

    Absolutely!

    An oscilloscope is an indispensable tool here!

    If capacitance issues do occur there are some ways to handle it

    there are also chips available for "extending" I2C buses where capacitance becomes a problem ...

    I would suggest adding a single slave at a time and make sure it all runs nicely

    Absolutely!

    As a general rule, always start simple - and work up...

Related