cancel
Showing results for 
Search instead for 
Did you mean: 

SP Dirver interface for LSM303D

mahesh2399
Associate
Posted on February 15, 2014 at 11:59

Hi,

I am looking for SPI driver interface for magnetometer LSM303D

thanks

#lsm303d-spi-driver
3 REPLIES 3
ferrarofcf
Associate II
Posted on October 22, 2014 at 11:10

Hi, I also....  You have found LSM303D.c and LSM303D.h?

maurizio23
Associate II
Posted on March 12, 2015 at 10:34

Me also waiting platform independant LSM303D.

Unfortunatly LSM303DLHC is different and the only solution is to upgrade\modify LSM303DLHC driver library.... long time spent for that

mikewilliamson9148
Associate
Posted on March 18, 2015 at 14:24

What processor or language do you need the driver for?  The SPI interface is very easy to use.  I'm trying* to use it with a Tiva LM4C129 processor, which has a SPI hardware module, but it's almost as easy to bit-bang.  Here are the basic routines in C for reading and writing LSM303D registers: (assuming your processor has SPI hardware)

uint8_t read_LSM303D_reg(uint8_t reg)

{

    uint8_t value;

    CLEAR_LSM303_CHIP_SELECT;

    SSI3_DR_R = reg|0x80; // send register number with 'read' bit set

    SSI3_DR_R = DUMMY_DATA;

    while (SSIBusy(SSI3_BASE));

    SET_LSM303_CHIP_SELECT;

    value = SSI3_DR_R;

    value = SSI3_DR_R;

    return (value);

}

void write_LSM303D_reg(char *name, uint8_t reg, uint8_t value)

{

    uint8_t temp;

    CLEAR_LSM303_CHIP_SELECT;

    SSI3_DR_R = reg;

    SSI3_DR_R = value;

    while (SSIBusy(SSI3_BASE));

    SET_LSM303_CHIP_SELECT;

    temp = SSI3_DR_R; // empty the FIFO

    temp = SSI3_DR_R;

}

Maybe that helps?

Patrick

* I said ''trying'' because the LSM303D is not behaving for us and we can't get any help from ST!  I can read and write the registers just fine, and I get good values for the accelerometer and magnetometer most of the time.  Once in a while, the accelerometer in the LSM303D seems to lock up such that the X and Z values are the same value and never change, and the Y value is usually the same value as X and Z but varies by +/- 1 or 2 every now and then.  The rest of the chip continues to work just fine, but the accelerometer is locked into this state, and it appears that no one at ST wants to address the issue.  Hope you don't run into the same problems?