0

Using Multiple ICM-20649
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Using Multiple ICM-20649

by JPCox on Sat Jul 31, 2021 10:53 pm

Hello,

I am trying to use multiple (2 at the moment) ICM-20649 sensors on the adafruit breakout board at the same time. I am using them to measure vibration, so sample rate and reliably capturing each data frame are important in my application. For this reason I have set up the devices using their interrupt pin and SPI communications.

I modified the adafruit library to allow me to enable the int1 pin by copying the setInt1ActiveLow method and modified it to write instead to the int1Enable register address:

Code: Select all | TOGGLE FULL SIZE
void Adafruit_ICM20X::setInt1Enable(bool enabled) {
 
  _setBank(0);
 
  Adafruit_BusIO_Register int_pin_cfg = Adafruit_BusIO_Register(
    i2c_dev, spi_dev, ADDRBIT8_HIGH_TOREAD, ICM20X_B0_REG_INT_ENABLE_1);
 
  Adafruit_BusIO_RegisterBits int1_enable =
    Adafruit_BusIO_RegisterBits(&int_pin_cfg, 1, 0);
 
  int1_enable.write(enabled);
}


I also added some register #defines that I needed for my custom readRegister();

I wrote my own SPI read method (readRegister() which you can find in the .ino code I include below) because the overhead from the library was too slow to read this sensor at its high sample rate (9kHz) and run some other functions I need in the final application. The SPI reads run in loop(), so that it is never called in an interrupt.

As for my hardware setup I am using a teensy 3.6, and two Adafruit ICM-20649 breakout boards. I can verify that these are working and wired correctly because each of these sensors can be made to work separately by uploading single-sensor versions that change the CS and interrupt pin.

The problem is when I try to enable reading on both of the devices after a short time one of the 20649s ceases working. After this, either device (seemingly random, though it seems to prefer one of the sensors sometimes) continues to work.

To try to resolve the issue, I tried using a polling method instead, with similar results (example code at the conclusion of this post shows polling version, but commented portions should show how to easily move back to an interrupt based approach).

I declared any variables modified in the interrupts as volatile without success.

I did notice that if I delayed the SPI read by at least one 20649 sample period (see if statements in the loop()), then both of the 20649s continued to be read, although missing every second sample.

Here is what that looks like on the serial monitor:

Code: Select all | TOGGLE FULL SIZE
Adafruit ICM20649 test!

ICM20649 1 found!

ICM1 configured

ICM20649 2 found!

ICM2 configured

setup_finished

read1

      641728

PSR1PSR2read2

      13

read1

      9

PSR1read1

      29

PSR1read1

      109

PSR1read1

      113

PSR1read1

      110

PSR1read1

      110

PSR1read1

      111

PSR1read1

      110

PSR1read1

      113

PSR1read1

      109

PSR1read1

      112

PSR1read1

      110

PSR1read1

      111

PSR1read1

      110

PSR1read1

      112

PSR1read1

      111

Attachments
Test_Multiple_Adafruit_ICM20649.ino
(6.5 KiB) Downloaded 1 time

JPCox
 
Posts: 1
Joined: Sat Jul 31, 2021 10:19 pm

Please be positive and constructive with your questions and comments.