Two I2C devices on separate I2C pins

FunkyD_
Wed Aug 16, 2017 2:13 pm
Hi there !

I am working with an MPU6050 IMU and a STM32 microcontroller. I am getting information from the IMU using jrowberg’s implementation (https://github.com/jrowberg/i2cdevlib/t … no/MPU6050). So far I had one MPU connected and it was working using HWire.

However, I would now need to use 2 MPUs and not on the same I2C (So, using I2C1 and I2C2 pins on maple mini board)
I first thought that we could have only one HWire working but I checked with a simple I2CScanner using 2 HWires and it is working. but when it comes to get it working with the I2Cdevlib implementation (that can be found also by following the link above), I have some troubles.

I also had a look here and from what I read I understand that there actually are some conflicts or a design ?

So did anyone manage to have 2 IMUs working with this library ?

Using HardWire seems good –> it was fast and I could use jrowberg’s implementation to get only the data I need (I would like to get MPU’s measurements at 1 KHz witout using FIFO buffer if possible)

Thanks for your help ! :mrgreen:


victor_pv
Wed Aug 16, 2017 2:31 pm
Could you link to the post about the conflict?

Also that thread is from 2015, so it’s possible it was using softwaire.

The hardware i2c has a limitation with interrupts. If using interrupts, the i2c ISR needs to have the highest priority or data may get corrupted.
The libmaple implementation sets the i2c interrupts to the higher priority, but also currently does not use the interrupts in anyway, so that should not affect you.

There may be conflicts with other pins. A good place to confirm any problem with the peripheral and possible work arounds is the errata sheets (there are several depending on the version of the MCU (flash size, manufacture data and what not).
This is the one for he xB MCUs (128KB of flash):
http://www.st.com/content/ccc/resource/ … 190234.pdf

You can also use DMA with i2c to reduce CPU overhead and skip using the i2c interrupts (you would instead use the DMA interrups, which do not have the same problem).


Pito
Wed Aug 16, 2017 2:44 pm
What would be the data throughput from both I2C1 and I2C2 at 1K samples per second?
How big (in bytes) is 1 sample?
Is that even feasible via 400kHz I2C clocked buses?

FunkyD_
Wed Aug 16, 2017 2:48 pm
I called it conflict but it actually only talks about issues.
Here it is : viewtopic.php?f=15&t=365#p3591

I am not using interruptions. I am just reading values from the MPU at 1 KHz (and I do not think that the code related to the IMU was using interruptions anyway).

I will come back to this post soon.
I found out that if you define an HardWire object which name is not HWire then Warnings appear at compilation time and uploading to Maple Mini makes it not responding (at least not detectable by Arduino IDE).

Si I don’t know yet whether a second HWire object (which would be called HWire2 for example) can work.

Anyway I will come back to this post :)


FunkyD_
Wed Aug 16, 2017 2:52 pm
[Pito – Wed Aug 16, 2017 2:44 pm] –
What would be the data throughput from both I2C1 and I2C2 at 1K samples per second?
How big (in bytes) is 1 sample?
Is that even feasible via 400kHz I2C clocked buses?

So there are 12 bytes for Acceleration and gyroscope (Ax, Ay, Az, Gx, Gy, Gz)
I was thinking about reading all of these for both IMUs and send through USB to computer for post-processing in a single Serial.write() as binaries.


zmemw16
Wed Aug 16, 2017 3:12 pm
sorry, i got the maple mini bit, but we need info
which platform win/mac/linux ?
which core, Arduino_STM32, ST_F1(??) ?
libmaple or hal preference ? :)
what ide version ? 1.6.x 1.8.x
odd thoughts occur, which module are you using, post a link maybe?
i’m wondering if it has an alternate address available?
have you confirmed that each is working on i2c1?

for myself, i look for sample code that shows how it’s done, not necessarily a cut and paste one; it doesn’t really matter whether it’s one from spl, hal or unicore-mx examples.
it’s the one that pops up with that ‘oh that’s how it’s done’ realisation having read it. :D

my way forward would be to look at the interrupt driven i2c hal examples.

stephen


FunkyD_
Wed Aug 16, 2017 3:36 pm
OK so problem partially solved :

So using 2 HWires is easy. but you need to name at least one of them ‘HWire’ otherwise you have the strange behaviours described above. This is certainly due to the implementation in i2cdevlib.
However, reading both acc x2 + gyro x2 and sending it through USb takes 1.25 ms approximately. (I can see if it is possible to optimize this but getting under 1ms will be hard if not impossible I think :? )

[zmemw16 – Wed Aug 16, 2017 3:12 pm] –
sorry, i got the maple mini bit, but we need info
which platform win/mac/linux ?
which core, Arduino_STM32, ST_F1(??) ?
libmaple or hal preference ? :)
what ide version ? 1.6.x 1.8.x
odd thoughts occur, which module are you using, post a link maybe?
i’m wondering if it has an alternate address available?
have you confirmed that each is working on i2c1?
stephen

I am working on Linux with arduino 1.6.11, the core is Arduino_STM32 !

Thanks ! :)


WindyYam
Wed Aug 16, 2017 3:56 pm
the mpu6050 have a pin to select i2c address 0x68 or 0x69. I think there are no need to use 2 wire devices as with Arduino wire lib you can use only one wire object to communicate at one time, there are no anything like multi-threading. instead, try connect them on the same bus, give them different address and init 2 mpu objects on different address params

FunkyD_
Thu Aug 17, 2017 8:14 am
[WindyYam – Wed Aug 16, 2017 3:56 pm] –
the mpu6050 have a pin to select i2c address 0x68 or 0x69. I think there are no need to use 2 wire devices as with Arduino wire lib you can use only one wire object to communicate at one time, there are no anything like multi-threading. instead, try connect them on the same bus, give them different address and init 2 mpu objects on different address params

Yes you’re right some manipulation on the MPU switches the address from 0x68 to 0x69.
But I am not sure that this can save you 0.20ms.

Also I thought that the MPU was storing the last values of Acceleration and Gyroscope it produced and that I was just asking to read those values with the microcontroller but it might be that both acceleration and gyroscope data are produced at request time from the microcontroller. This could save me enough time.


RogerClark
Thu Aug 17, 2017 10:59 am
If you need faster data rates, you should probably use SPI, however I don’t think that devices supports SPI, but AFIK the 9150 and 9250 support SPI

zmemw16
Thu Aug 17, 2017 11:55 am
6050 is just i2c
scroll down to Trick heading in
https://playground.arduino.cc/Main/MPU-6050#multiple
srp

WindyYam
Fri Aug 18, 2017 8:29 am
[FunkyD_ – Thu Aug 17, 2017 8:14 am] –
but it might be that both acceleration and gyroscope data are produced at request time from the microcontroller.

i think mpu output contintuous when in fifo mode, if not it produce data at request time, and the delay are the sampling time.


Leave a Reply

Your email address will not be published. Required fields are marked *