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

Twi configuration for multiple slave devices

Hello,

I'm trying to configure two TWI slave devices on the same TWI bus on my custom board(nRF52832). One slave is RTC, and the other is a biosensor. The TWI configuration for RTC seems to work. So I adopt the similar configuration and switch to corresponding SCL, SDA pins for biosensor, but the initialization of custom board just stuck at bio_twi_init().

I've searched the devzone for relevant issues but still can't find the solution. TWI initialization sample code is as two_twi_slaves_main.c, please ignore whether it can be compiled.

Any suggestion would be great appreciated!

Many Thanks in advance!

Parents
  • Hi,

    The reason why your code is not working, is that you are initializing two TWI interfaces on the same serial interface. One address only support one interface at the time. You can see which addresses support which interfaces on this page.

    You need to change the line:

    static const nrf_drv_twi_t m_twi_bio = NRF_DRV_TWI_INSTANCE(0);
    

    to:

    static const nrf_drv_twi_t m_twi_bio = NRF_DRV_TWI_INSTANCE(1);
    

    Best regards,

    Jørgen

  • Are you able to provide a trace of the transfer from a logic analyzer? I haven't worked with AS7000, but if the transmission is aborted due to a NACK, it might be busy. Maybe you can ask the developer of the sensor?

  • i have two slaves connected on the same I2C pins on NRF52-DK, i created two I2C instances but i am unable to read/write to the two slaves, if i enable the two instances I2C stops working, does this mean that i need to share the same I2C instance for both slaves?

  • Tested my case with one TWI instance shared for both slaves, it works... So for future reference for everyone interested, if you are using only two I2C pins to connect multiple slaves you need only one TWI instance, otherwise if you are connecting the slaves on different I2C pins you need multiple TWI instances...

  • So, as I understand it, in Nordic Thingy 52 application,

    - all sensors except the motion sensor (lis2dh12) are interfaced on one TWI bus (TWI_SCL and TWI_SDA)

    - while the motion sensor is interfaced to a different TWI bus (TWI_SCL_EXT andd TWI_SDA_EXT)

    For each instance a dedicated nrf_drv_twi_init() is required?

    For each individual sensor on a TWI bus a dedicated event handler is also required so that it works in non-blocking mode.

    So, suppose I want to interface an I2C sensor to the default Nordic Thingy 52 application:

    1. I should physically connect the sensor with TWI external bus (TWI_SCL_EXT and TWI_SDA_EXT)

    2. I should use the TWI external bus instance to initialize the config params and event handler.

    How come the Nordic Thingy 52 application have same twi_instance for motion sensor as that of other sensors?

Reply
  • So, as I understand it, in Nordic Thingy 52 application,

    - all sensors except the motion sensor (lis2dh12) are interfaced on one TWI bus (TWI_SCL and TWI_SDA)

    - while the motion sensor is interfaced to a different TWI bus (TWI_SCL_EXT andd TWI_SDA_EXT)

    For each instance a dedicated nrf_drv_twi_init() is required?

    For each individual sensor on a TWI bus a dedicated event handler is also required so that it works in non-blocking mode.

    So, suppose I want to interface an I2C sensor to the default Nordic Thingy 52 application:

    1. I should physically connect the sensor with TWI external bus (TWI_SCL_EXT and TWI_SDA_EXT)

    2. I should use the TWI external bus instance to initialize the config params and event handler.

    How come the Nordic Thingy 52 application have same twi_instance for motion sensor as that of other sensors?

Children
Related