I’m using photon imu shield.
I already tested it in I2C mode. It works fine.
But i have problem about using SPI mode.
as it mentioned, i cut former traces and close jumpers.
and using SPI example code, i tested. But it didn’t work
it print fail message.
so, i checked mTest and xgTest value in begin function(SparkFunLSM9DS1.cpp).
mTest value is 61 and xgTest value is 60.
( also, i checked these value in I2C mode.
mTest value is 61 same, but xgTest is 104. )
so, i think becasue of reading wrong xgTest value, it makes whoAmICombined value is wrong
uint16_t whoAmICombined = (xgTest << 8) | mTest;
if (whoAmICombined != ((WHO_AM_I_AG_RSP << 8) | WHO_AM_I_M_RSP))
return 0;
so, it return 0.
SPI mode failed.
what am i wrong?
let me know how to use SPI mode (hardware setting and code everything help).
When you say you cut the traces and bridged the jumpers, how did you do this for the CS pins?
Which pin have you set to be your CS pins, and have you adapted the code accordingly (if needed)?
Any chance to shoot a clear, high quality pic of the jumper side of your board?
///////////////////////
// Example SPI Setup //
///////////////////////
// Define the pins used for our SPI chip selects. We're
// using hardware SPI, so other signal pins are set in stone.
#define LSM9DS1_M_CS A2 // Can be any pin
#define LSM9DS1_AG_CS A1 // Can be any other pin
It looks good, maybe you just measure the cut connections if they are really completely open.
And while you at it, just see if you’ve got connection between the jumper and the respective open solder pads.
If I get round to it, I could set one of my IMU shields up for SPI to test - might take a while
I checked the cut connections by using multimeter that are completely open, also between the jumper and open solder pads.
As i mentioned at first, there is reading error (or communication error) of xgTest value.
mTest value ( written in Function begin() SparkFunLSM9DS1.cpp) is same as I2C mode ( value is 61).
but xgTest value is different. When SPI mode, the value is 60, in I2C mode the value is 104.
I think the value in SPI mode should be 104 . then it make whoAmICombined value right.
So, it will work fine.
I want to see your IMU shields result with SPI. ASAP
Yup, I can confirm your finding now. I’ve got the same message.
I’ll look a bit deeper into the code too and file an issue at SparkFun - or you can too.
On my shield it even seems to be a hardware issue. Could you please check if your shield has a short between A1 and A2?
How lucky, I had to pick the worst one I had, with the short between the two CS pins underneath the actual LSM3D chip (not repairable for me )
But lucky for you when I tried another one, I found out, that the problem is due to the Photons extra speed, which results in a too high SPI speed.
The way around this looks like this
void LSM9DS1::initSPI()
{
pinMode(_xgAddress, OUTPUT);
digitalWrite(_xgAddress, HIGH);
pinMode(_mAddress, OUTPUT);
digitalWrite(_mAddress, HIGH);
SPI.begin();
// Maximum SPI frequency is 10MHz, could divide by 2 here:
//SPI.setClockDivider(SPI_CLOCK_DIV2); // <-- 120Mhz Photon results in faulty behaviour
SPI.setClockDivider(SPI_CLOCK_DIV4); // this works for Photon
//SPI.setClockSpeed(10, MHZ); // this would be HW independent, but
// only supported on FW >= 0.4.5
// Data is read and written MSb first.
SPI.setBitOrder(MSBFIRST);
// Data is captured on rising edge of clock (CPHA = 0)
// Base value of the clock is HIGH (CPOL = 1)
SPI.setDataMode(SPI_MODE0);
}
I changed code like that.
So, it works fine.
Thank you so much.
(Also, my one is damaged for setting hardware to make spi mode. Because of damaged pattern, it can’t use I2C and SPI )
Anyway, another one is fine .
Thank you