SPI Interfacing problems with LSM9DS1

Hello everyone,

Currently, I am trying to integrate my LSM9DS1 on a self made PCB board. I tested every connection thoroughly and everything seems to be connected in the proper way. I also tested my code just by connecting the LSM9DS1 with jumper cables to the arduino UNO and it works as it should work.

However, when I am finally soldering the LSM9DS1 onto the PCB board and try to read it , the measurement of the Gyroscope and Accelerometer seem to be just a random walk. While the Magnetometer readings are just fine. If I connect one Jumper cable from the SDO M or AG (Just one doesn’t matter which one) to the MISO port on the UNO everything seems to work fine again. I would think this is an error in the soldering, but when checking with the Multimeter everything seems to be just fine. I even tried to lay another cable (short cut) from the SDO to the microconnector didn;t work.

I basically can not figure out what is wrong with my PCB board here. It seems to have only problems with the SDO connection. But for Hardware SPI you had to connect them to eachother, which I did. They only difference actually between the model with just Jumper cables and the PCB board is that there is an Micro-connecter in between. Could this raise any problems with the SDO connection?

The thing is I cannot have a jumper cable but need strong connections since it has to work under high G forces and vibrations.

Figures of the Set-up can be found in the Attachment and the code can be found below, If you need more information feel free to ask.

Code:

#include <SPI.h>

const int CLK = 13;
const int SDO = 12;
//const int SDA = 11;
const int CSM = 9;
const int CSAG = 10;

void setup() {
Serial.begin(115200);
// put your setup code here, to run once:
pinMode(CSM, OUTPUT);
pinMode(CSAG, OUTPUT);
digitalWrite(CSM, HIGH);
digitalWrite(CSAG, HIGH);
SPI.begin();

//DDRB |= 0x07; //Set pin 8-13 till Output
//PORTB &= 0xF8; //Set pin 8-11 low

// soft reset & reboot accel/gyro
write8(true, 0x22, 0x05);
// soft reset & reboot magnetometer
write8(false, 0x21, 0x0C);
delay(10);

// enable gyro continuous
write8(true, 0x10, 0xD8); // on XYZ and set range for gyro

// ACCELEROMETER SETUP
write8(true, 0x1F, 0x38); // enable X Y and Z axis
write8(true, 0x20, 0xC0); // 1 KHz out data rate, BW set by ODR, 408Hz anti-aliasing, Last one sets the range of the accelerometer

// MAG SETUP
write8(false, 0x22, 0x00); // continuous mode
write8(false, 0x20, 0xFC); // high perf XY, 80 Hz ODR
write8(false, 0x23, 0x0C); // high perf Z mode

// Set default ranges for the various sensors
write8(false, 0x21, (0b00 << 5)); // SET RANGE MAGNETOMER 4 GAUSS
}

void loop() {
byte buffer[6];
readBuffer(true,
(0x80 | 0x28),
6, buffer);
uint8_t xlo = buffer[0];
int16_t xhi = buffer[1];
uint8_t ylo = buffer[2];
int16_t yhi = buffer[3];
uint8_t zlo = buffer[4];
int16_t zhi = buffer[5];
xhi <<= 8; xhi |= xlo;
yhi <<= 8; yhi |= ylo;
zhi <<= 8; zhi |= zlo;
Serial.print(xhi);Serial.print(’\t’); Serial.print(yhi); Serial.print(’\t’); Serial.println(zhi);
readBuffer(true,
0x80 | 0x18,
6, buffer);
readBuffer(false,
((0x80 | 0x28) | 0x40),
6, buffer);
delay(1000);

}

void write8(boolean type, byte reg, byte value)
{
byte _cs;

if (type == true) {
_cs = CSAG;
} else {
_cs = CSM;
}
SPI.beginTransaction(SPISettings(2000000, MSBFIRST, SPI_MODE0));
digitalWrite(_cs, LOW);
spixfer(reg & 0x7F); // write multiple
spixfer(value);
SPI.endTransaction();
digitalWrite(_cs, HIGH);

}

uint8_t spixfer(uint8_t data) {
return SPI.transfer(data);
}

byte readBuffer(boolean type, byte reg, byte len, uint8_t *DATA)
{
byte _cs;

if (type == true) {
_cs = CSAG;
} else {
_cs = CSM;
}
SPI.beginTransaction(SPISettings(2000000, MSBFIRST, SPI_MODE0));
digitalWrite(_cs, LOW);
// set address
spixfer(reg | 0x80); // read multiple
for (uint8_t i=0; i<(len); i++) {
DATA = spixfer(0);

Dirt in the connector? With a 'scope you could look at the signal at each end and this
can tell you more than just continuity tests.

Have you tried much short wires between board and Arduino, fast logic doesn't like long
stray wires, especially without decent ground returns (A common way to connect boards is
with IDC ribbon connectors, using every 2nd or 3rd wire as ground).

Also its worth trying a lower SPI clock rate.

Thanks for the reply!

Yes I normally use a slower SPI clock rate, in the code here was just what I just tested haha.

I made now I cable which is the half of the length it was before, this seems to work. Still I found it a bit strange that like 50% of the time in the previous set-up it was working properly and the other 50% it was doing the random walk.

But problem solved thanks!

How is this supposed to help anyone reading it if there are no INITIAL CABLE LENGTH and FINAL CABLE LENGTH measurements posted ? Are they supposed to guess what those values were/are ?