Interfacing LSM9DSO with SPI interface

Discussion in 'Embedded Systems and Microcontrollers' started by charlesdavid, May 17, 2015.

  1. charlesdavid

    Thread Starter New Member

    May 17, 2015
    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

    My C++ code:
    Code (Text):
    2. #include "mbed.h"
    3. #define LSM9DS0_WHO_AM_I_G  0x0f
    5. int main()
    6. {
    7.     int whoami1;
    8.    SPI spi(PIN_SPI_MOSI,PIN_SPI_MISO,PIN_SPI_CLK); // Creating spi instance
    9.    DigitalOut cs_xm(PIN_SPI_CS1); // Creating cs instance for accelerometer.
    11.    spi.frequency(10000000); // fcy supported by slave,so setting that as SPI clk.
    12.    spi.format(8,0);
    14.    cs_xm=0;
    15.    spi.write(0x8f);  //Command for Acc/Mag ID read.
    17.    whoami1 = spi.write(0x00);
    18.    cs_xm=1;
    20. }
    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
    Last edited by a moderator: May 17, 2015