Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
6 years, 6 months ago.
I have SPI connection Problems with the LSM6DS3
Hey, I bought a LSM6DS3 Board at sparkfun.
Here is the datasheet to the board: More about SPI https://www.st.com/resource/en/datasheet/lsm6ds3.pdf
Connection: 3V3 - 3V3 GND - GND SCL-p13 SDA(SDI)-p11 CS-p14 SA0-p12
My Programm returns everytime 0x7F
Here is my Code:
its not working :(
#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);
uint8_t result;
while(1){
//Select chip
cs = 0;
//Read (0x80||Address)
//Write (0x00||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);
// Deselect the device
}
}
1 Answer
6 years, 6 months ago.
Hi there,
you can try to find a library or a Demo here on the Mbed web. For example...
Import libraryLSM6DS3
LSM6DS3 Library
Import programLSM6DS3_Demo
Demo for LSM6DS3
However, I can not test it because I do not have this Sparfun board but when I check your spi.write
Spi.write
spi.write(0x8F);
are you sure with 0x8F?
- according to the datasheet what you posted https://www.st.com/resource/en/datasheet/lsm6ds3.pdf any command or address 0x8f not exist.
- correct address of the WHO_AM_I register is 0x0F according to the data sheet - page 53 (9.11).
Best regards
J.
1) I already tried the Libary. But it is only for I2C. I2C is working well but i want to use SPI. 2) The Spi Write command should be sperated to 0x80 for reading and 0x0F for WHO_AM_i register. So you get, if you want to read the WHO_AM_I register, 0x8F.
posted by 28 May 2019Ah sorry, my mistake, but still exist another one with both interfaces https://os.mbed.com/teams/adamchuang/code/LSM6DS3/file/c19d384b2896/LSM6DS3.h/
posted by 29 May 2019