Hi,
I am trying to drive LSM9DS0( Accelerometer & Magnetometer,Gyroscope) sensor using SPI interface on custom built board. We are using mbed OS for developing the driver for that.Before starting to write actual driver, i am trying just to read the ID of the device through the SPI APIs of mbed OS.(As specified in https://developer.mbed.org/handbook/SPI).
My C++ code:
I compiled the above code and flashed.
Using Oscilloscope , i probed the CS,MOSI,CLK pins and i was able to see the clock and the corresponding MOSI data going when CS is low. I am supposed to get the ID of the Accelerometer in the whoami1 variable,which i am not getting.I have double verified the command to read ID is right.
I see the SPI master's transactions to the slave sensor, but the sensor doesn't respond back.
Being a novice, i am not able to get where am i going wrong.Any help would be gladly appreciated.
Thanks in advance.
Moderators note : Please use code tags for pieces of code
I am trying to drive LSM9DS0( Accelerometer & Magnetometer,Gyroscope) sensor using SPI interface on custom built board. We are using mbed OS for developing the driver for that.Before starting to write actual driver, i am trying just to read the ID of the device through the SPI APIs of mbed OS.(As specified in https://developer.mbed.org/handbook/SPI).
My C++ code:
Code:
#include "mbed.h"
#define LSM9DS0_WHO_AM_I_G 0x0f
int main()
{
int whoami1;
SPI spi(PIN_SPI_MOSI,PIN_SPI_MISO,PIN_SPI_CLK); // Creating spi instance
DigitalOut cs_xm(PIN_SPI_CS1); // Creating cs instance for accelerometer.
spi.frequency(10000000); // fcy supported by slave,so setting that as SPI clk.
spi.format(8,0);
cs_xm=0;
spi.write(0x8f); //Command for Acc/Mag ID read.
whoami1 = spi.write(0x00);
cs_xm=1;
}
Using Oscilloscope , i probed the CS,MOSI,CLK pins and i was able to see the clock and the corresponding MOSI data going when CS is low. I am supposed to get the ID of the Accelerometer in the whoami1 variable,which i am not getting.I have double verified the command to read ID is right.
I see the SPI master's transactions to the slave sensor, but the sensor doesn't respond back.
Being a novice, i am not able to get where am i going wrong.Any help would be gladly appreciated.
Thanks in advance.
Moderators note : Please use code tags for pieces of code
Last edited by a moderator: