cancel
Showing results for 
Search instead for 
Did you mean: 

LSM6DS3 SPI Communication Problem

ogris
Associate II

I tried to work with mbed LPC1768 and LSM6DS3-Dev-Board from Sparkfun.

The connections:

uC - LSM6DS3

VOUT 3V3 regulated Out - 3V3

GND-GND

SCLK-SCL

MOSI-SDA (SPI SDI)

MISO-SA0

CS-CS

The Code:

#include "mbed.h"
 
Serial pc(USBTX,USBRX);
SPI spi(p11, p12, p13); // mosi, miso, sclk
DigitalOut cs(p14);
 
 
int main() {
    pc.baud(115200);
    pc.printf("Start");
    spi.format(8,3);
    spi.frequency(100000); 
    // Select the device by seting chip select low
    cs = 1;
    wait(1); 
    
    //Set Register to Default Mode
    //Set SPI to 4 Wire-Mode
    cs = 0;
    spi.write(0x12);
    spi.write(0x04);
    cs = 1;
    wait_ms(1);
    
    uint8_t result;       
    while(1){
        //Select chip
        cs = 0;
        //address
        spi.write(0x8F);
        // send a dummyvalue of 0 to read the first byte returned:
        result = spi.write(0x00);
        //deselect chip
        cs = 1;
        // Send 0x8f, the command to read the WHOAMI register
        printf("WHOAMI register = 0x%X  \n ", result);
         wait_ms(1);
    }
}

It returned 0x7F every time.

I checked all bits with the Osziloskop.

Channel 1 - yellow, Channel 2 - blue

Name <Channel1>_<Channel2>

6 REPLIES 6
S.Ma
Principal

Answer in the spec. Read well...

S.Ma
Principal

0690X000008aI04QAE.png

ogris
Associate II

<Cant delete this Comment>

ogris
Associate II

Well, my English is not the best.

How i thinks it works:

In Setup i write ( 0x00<write>||0x12<registeraddr>) to say i want to write to this CTRL3 register.

And then I write 0x04 to set the bits. -> 0x04 means SPI on 4-Wire mode.

Then I write (0x80<Read>||0x0F) for Who_is_me.

At the end i send dummybites to shift the answer to my uC and print it out.

S.Ma
Principal

Yep, this sensor default after power on to 4 wire mode.

If you want 3 wires, you must write SIM bit first, then do the reading.

ogris
Associate II

I want 4 wires and the settings are on 4 wires but i still get no data.

If you look on the osziloskop-Pictures you will see that something is wrong.