Problem: multi LSM6DSOX SPI wiring with Arduino Due

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
KKneipe
 
Posts: 5
Joined: Mon Feb 27, 2023 7:36 am

Problem: multi LSM6DSOX SPI wiring with Arduino Due

Post by KKneipe »

Hello everyone,
I am working on a project, trying to connect several LSM6DSOX with Arduino Due. For convenience I used the SPI mode. But I had some problem here: there was no problem with only one LSM6DSOX communicating with Arduino, but there would be problem when two LSM6DSOX connected.

For wiring: I used the SPI-header of the Arduino to connect sensors (SDA, SCL, DO). For CS pins I choose the digital Pin of Arduino.

For coding: I used mainly the example code provided from adafruit. https://learn.adafruit.com/lsm6dsox-and ... mu/arduino
But I did some change as below. (Because the problem occurs here, so I didn't post the code after that)

Code: Select all

for (int i = 0; i++; i < 2){ //For only one sensor, change the number to one
	if (!sox[i].begin_SPI(LSM_CS[i], LSM_SCK, LSM_MISO, LSM_MOSI)) {
		Serial.print("Failed to find LSM6DSOX chip: ");
		Serial.println(i);
		while (1) {
			delay(10);
		}
	}
}
Result: When only one LSM6DSOX is connected, the SPI works well. But when there are two LSM6DSOX connected, even the first "begin_SPI()" will return FALSE. (So it will print "Failed to find LSM6DSOX chip: 0")

I thought it may because of the interference of the second sensor. I tried to set the CS pin of the second one to high at very beginning, but the problem is not solved. Hoping if someone can help me with it. Thanks in advance.

User avatar
adafruit_support_carter
 
Posts: 29170
Joined: Tue Nov 29, 2016 2:45 pm

Re: Problem: multi LSM6DSOX SPI wiring with Arduino Due

Post by adafruit_support_carter »

SPI shares the MOSI, MISO, and SCLK pins. But each device needs its own CS pin.

Are you using a separate CS pin for each LSM6DS0X connected?

User avatar
KKneipe
 
Posts: 5
Joined: Mon Feb 27, 2023 7:36 am

Re: Problem: multi LSM6DSOX SPI wiring with Arduino Due

Post by KKneipe »

adafruit_support_carter wrote: Mon Feb 27, 2023 12:39 pm SPI shares the MOSI, MISO, and SCLK pins. But each device needs its own CS pin.

Are you using a separate CS pin for each LSM6DS0X connected?
I used pin#22 as the CS pin for the first LSM6DSOX and pin#24 as the CS pin for the second one.
After finishing the wiring, I have tried to set the CS pin of the second one high or low at the beginning of the code. But neither will prevent the failure of "beginSPI". I was wondering if the CS pin really works before initializing (I mean "beginSPI" here).

User avatar
adafruit_support_carter
 
Posts: 29170
Joined: Tue Nov 29, 2016 2:45 pm

Re: Problem: multi LSM6DSOX SPI wiring with Arduino Due

Post by adafruit_support_carter »

The datasheet is a little vague on the specifics of the other pins behavior when the CS pin is high (1):
ds.png
ds.png (70.32 KiB) Viewed 185 times
Wonder if maybe the other shared pins are somehow going back to I2C mode? It's not clear if "SPI idle mode" is a separate unique mode from "I2C communications enabled". Or if it's both at the same time?

What if you try a basic single sensor example:
https://learn.adafruit.com/lsm6dsox-and ... mu/arduino
and manually tie one of the two sensor's CS pin high?

User avatar
KKneipe
 
Posts: 5
Joined: Mon Feb 27, 2023 7:36 am

Re: Problem: multi LSM6DSOX SPI wiring with Arduino Due

Post by KKneipe »

adafruit_support_carter wrote: Mon Feb 27, 2023 2:32 pm The datasheet is a little vague on the specifics of the other pins behavior when the CS pin is high (1):
ds.png

Wonder if maybe the other shared pins are somehow going back to I2C mode? It's not clear if "SPI idle mode" is a separate unique mode from "I2C communications enabled". Or if it's both at the same time?

What if you try a basic single sensor example:
https://learn.adafruit.com/lsm6dsox-and ... mu/arduino
and manually tie one of the two sensor's CS pin high?
Thanks for the quick replying!

I can explain my attempts more in detail.
  • 1st attempt:
    Wiring: one sensor connected, CS 0 connected to pin#22
    Code I provide: set the i < 1, which means beginning the SPI on CS 0.
    Result: Sensor communicates well.
  • 2nd attempt:
    Wiring: two sensors connected, CS 0 connected to pin#22, CS 1 connected to pin#24
    Code I provide: set the i < 2, which means beginning the SPI on CS 0 and on CS 1.
    Result: printout "Failed to find LSM6DSOX chip: 0", which means the beginning of SPI of first one failed.
    (In this case, the code has run is just same as the simple code you provided? Since it iterated only once)
  • 3rd attempt:
    Wiring: two sensors connected, CS 0 connected to pin#22, CS 1 connected to 5V
    Code I provide: same as 2nd attempt
    Result: same as 2nd attempt
  • 4th attempt:
    Wiring: two sensors connected, CS 0 connected to pin#22, CS 1 connected to GND
    Code I provide: same as 2nd attempt
    Result: same as 2nd attempt
In conclusion, the CS pin of the second sensor doesn't seem to influence before setup.

User avatar
adafruit_support_carter
 
Posts: 29170
Joined: Tue Nov 29, 2016 2:45 pm

Re: Problem: multi LSM6DSOX SPI wiring with Arduino Due

Post by adafruit_support_carter »

Just to make sure, you are using this breakout?
https://www.adafruit.com/product/4438

User avatar
KKneipe
 
Posts: 5
Joined: Mon Feb 27, 2023 7:36 am

Re: Problem: multi LSM6DSOX SPI wiring with Arduino Due

Post by KKneipe »

adafruit_support_carter wrote: Mon Feb 27, 2023 3:46 pm Just to make sure, you are using this breakout?
https://www.adafruit.com/product/4438
Yes

User avatar
adafruit_support_carter
 
Posts: 29170
Joined: Tue Nov 29, 2016 2:45 pm

Re: Problem: multi LSM6DSOX SPI wiring with Arduino Due

Post by adafruit_support_carter »

For the sake of testing, can you write a very simple test sketch that explicitly sets up each LSM6DSOX, instead of using the sox and LSM_CS arrays. Ex:

Code: Select all

Adafruit_LSM6DSOX sox1;
Adafruit_LSM6DSOX sox2;
and in setup():

Code: Select all

  if (!sox1.begin_SPI(CS1, LSM_SCK, LSM_MISO, LSM_MOSI)) {
    Serial.println("Failed to find LSM6DSOX chip 1");
    while (1);
  }
  if (!sox2.begin_SPI(CS2, LSM_SCK, LSM_MISO, LSM_MOSI)) {
    Serial.println("Failed to find LSM6DSOX chip 2");
    while (1);
  }
and see if you get the same behavior.

And just to check - why the use of software SPI instead of hardware SPI?

User avatar
KKneipe
 
Posts: 5
Joined: Mon Feb 27, 2023 7:36 am

Re: Problem: multi LSM6DSOX SPI wiring with Arduino Due

Post by KKneipe »

adafruit_support_carter wrote: Mon Feb 27, 2023 4:28 pm For the sake of testing, can you write a very simple test sketch that explicitly sets up each LSM6DSOX, instead of using the sox and LSM_CS arrays. Ex:

Code: Select all

Adafruit_LSM6DSOX sox1;
Adafruit_LSM6DSOX sox2;
and in setup():

Code: Select all

  if (!sox1.begin_SPI(CS1, LSM_SCK, LSM_MISO, LSM_MOSI)) {
    Serial.println("Failed to find LSM6DSOX chip 1");
    while (1);
  }
  if (!sox2.begin_SPI(CS2, LSM_SCK, LSM_MISO, LSM_MOSI)) {
    Serial.println("Failed to find LSM6DSOX chip 2");
    while (1);
  }
and see if you get the same behavior.

And just to check - why the use of software SPI instead of hardware SPI?
Thanks for the advice! I will show you the result when I tried.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”