Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

TWI Manager / Sensor interfacing with register-less sensor

Hi everyone,

I'm having trouble deciding on the "best" / "most sane" way to interface two I2C sensors with the nRF5832.

Both sensors are on the same I2C bus. The first sensor is well supported by the nRF52 SDK v15.0.0 with a driver using the TWI Manager and Sensor libraries.

The second sensor is as primitive as it gets (and as far as I have seen there is no driver in the nRF52 SDK):
    no registers
    to configure the sensor you write some command byte to the sensor's address
    to read some measurements, you send the appropriate command byte to the sensor's address, wait some time, and finally perform a read for x bytes on the sensor's address

So far I managed to interface both sensors separately: the first one with the provided driver, the second one using the nrf_twi_drv driver.

I've tried to port the first sensor's driver to the nrf_twi_drv driver which worked (but I'm not to fond of the idea to rewrite the nrf_twi_sensor based driver to use the nrf_twi_drv driver) and I also tried to expand the TWI Sensor library to cope with the absence of registers and the requirement to wait for a given time which wasn't as successful.

How do I interface them both at the same time, ideally with a single solution / way of interfacing?
    
Kind regards

lhochstetter

Parents Reply Children
  • Hi,
    Unfortunately, i'm not so sure if this is as straight forward as one would think since the LIS2DH12 is based on nrf_twi_sensor which use the nrf_drv_twi at a lower layer.The easiest solution would be to have to separate TWI instances for the devices. Using a single instance might require you to init and de initialize the driver between every transfer when you switch device. You can maybe avoid the init and de init when you switch between the devices by re-creating the state the peripheral was in before you switched device. 
     
    Jared 
  • Hi Jared,

    thanks for your input! Just to be sure I understand you correctly:

    I'd be using TWI 0 and TWI 1 on the same SDA and SCL pins (Note: both sensors are on the same I2C bus): TWI 0 would be used by the LIS2DH12 and TWI 1 would be used by the MS5607.

    i.e.

    TWI 0-|                   |-LIS2DH12
          |----|SDA + SCL|----|
    TWI 1-|                   |-MS5607


    How do I guarantee in this case, that e.g. a transfer on TWI 0 does not interfere with a ongoing transfer on TWI 1 or vice versa?

    Or did your suggestion inclue two separate I2C buses / separate SDA and SCL lines? If so, I cannot use your solution as I'm bound by the hardware design.

    i.e.

    TWI 0-|----|SDA + SCL|----|-LIS2DH12
    
    TWI 1-|----|SDA + SCL|----|-MS5607


    I might just port the LIS2DH12 driver to use the nrf_drv_twi functions if I can't come up with another idea.

    Kind regards,

    lhochstetter

  • Hi,

    Sorry for the late response. Unfortunately, I meant using two separate lines. Each instance requires two unique pins.

    On the other hand, I've might have given an impression in my previous reply that using one instance is more complicated then it really is. 

    What you would have to do to use one instance with two separate drivers is to use one of the initialize functions of either driver to initialize the instance, and then use the same instance when calling functions from either driver. It's important that you only initialize the instance once and don't use the instance in a operation with one driver when it's already busy in another operation with the other driver. This could give unpredictable behavior. I would recommend that you use the initialize function from the nrf_twi_sensor to initialize the instance, as it use the transaction manager which again use nrf_drv_twi. The transaction manager will reinitialize every time the config parameters changes from the previous transaction, using another configuration outside of the driver can therefore give error. 

    lhochstetter said:
    I might just port the LIS2DH12 driver to use the nrf_drv_twi functions if I can't come up with another idea.

    This should be a viable option. But I think the best and safest option would be to base the MS5607 on the nrf_twi_mngr driver instead of the nrf_twi_drv. 

    Regards

    Jared 

  • Hi Jared,

    thanks again for your input!

    But I think the best and safest option would be to base the MS5607 on the nrf_twi_mngr driver instead of the nrf_twi_drv. 

    I skimmed the nrf_twi_mngr documentation and noticed that you can actually perform quite "low level" I2C transactions (i.e. the nrf_twi_senor allows you only to read a register but not from an I2C address, but the nrf_twi_mngr seems to be less restrictive).

    This might be an option to interface both the MS5607 and the LIS2DH12 using the nrf_twi_mngr ... I'll definetly try!

    Thanks and kind regards

    lhochstetter

Related