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

nrfx_TWI to access Bosch BNO055... low-level ops needed

I'm using nRF52832 and intend to interface 3 I2C slave devices; the first is the BNO055 IMU.

I've integrated the Bosch "driver" code into my SES project, but I find that their "low-level" code

(that would actually use the I2C) is just "stubs".  The key methods that need to be implemented

are: 

BNO055_I2C_bus_write and BNO055_I2C_bus_read.

My intent was to plug in "TWI" operations to accomplish this; I've gone 'round and 'round with

all of the "TWI legacy" stuff like "nrf_drv_twi_xxx" vs "nrfx_twi_xxx" and believe that the "nrfx..."

(under "..\modules", not "..\components" (which seems "deprecated") is probably the way to go.

But I'm kinda stuck here.   Some questions:

  a) is this the right way to proceed?

  b) has anyone already done this? ("nrfx TWI" to BNO055)

  c) If I'm using nRF52832 as "master", I'm thinking that I don't need any of the "TWIS" mechanism,

   as I'm only talking to external "slave" devices, not trying to use the '52 "as" a slave, correct?

  d) will H/W TWI deal with async responses from multiple I2C slaves "concurrently" (I'm unclear

on how "arbitration" might work in this scenario), or must I resort to synchronous, sequential "polling"

style of device access?

Thanks so much for any direction & suggestions!

Jim

  • Hi,

    It sounds like you got most of it correct.

    a) Yes. I understand your confusion though. Issues related to mixed legacy and nrfx drivers is a common topic on devzone these days. If you are starting a new project now I suggest that you use the nrfx drivers. In my experience, the TWI master driver documentation is applicable for the nrx drivers, just substitute all occurrences of nrf_drv_twi with nrfx_twim. You can read more about nrfx here

    b) I couldn't find any finished libraries or anything, but at least you are not the first to first to ask about BNO055 here on devzone.

    c) That is correct. 

    d) If the nRF52 is the only master on the bus (which it usually is), you don't need to worry about that. It is the master that is responsible for initiating all communications, and the slaves should never start "talking" unless spoken to. I see that the BNO055 has an interrupt pin that it can use to notify the master that new data is available, but the way it usually works is that the interrupt pin trigger an interrupt in the master, and then the master decides when to read the data. 

    Here is some good documentation on the I2C protocol: https://www.i2c-bus.org/

  • Hi Martin,

     Thanks for your quick reply!  I think I'm getting in-sync here.  Re: my question/your reply "(d)", the usage that I envision for my multiple slave I2C devices is ideally for them to operate completely asynchronously; e.g. commands sent to Device-A upon Timer1 firing, commands sent to Device-B upon Timer2 firing.  If I understand TWI correctly, it looks like I could have two nrfx_twi_t instances (TWIM0, TWIM1 enabled), each having their own nrfx_twi_config_t thereby specifying different pairs of I/O's for scl,sda, and independent nrfx_twi_evt_handler_t's.   I hope I'm not too far off base with this, else I'll need to take a step back. :)  Make sense?

    Jim

  • Yes, you have got that right too. The nRF52832 has two sepparate TWI instances which can be used completely independently of each other. 

  • Hi,

    I am currently trying to make the BNO055 running with my nRF53832-DK... I guess I know the theory about I2C and I also understood the section in the datasheet of the BNO sensor. But I have absolutely no idea how I have to implement the BNO055_I2C_bus_write and BNO055_I2C_bus_read functions in my Keil project... 

    Did someone write these functions and would be willing to share them? This would be very helpful for me to learn how it really works.

    Greetings from Switzerland

    Michael

Related