cancel
Showing results for 
Search instead for 
Did you mean: 

I use STM32F108C8T6’s SPI to communicate with LSM6DSM. First, I read the id 10 times, only the second time it returns correct, the rest is wrong, why?

blian.1
Associate

0693W000006GDxWQAW.png0693W000006GDxRQAW.png0693W000006GDxMQAW.png0693W000006GDxHQAW.png

2 REPLIES 2
Eleon BORLINI
ST Employee

Hi @blian.1​ ,

Please note that the SPI read command is performed with 16 clock pulses, so if you place in a loop the SPI single register reading command, you have to send the command for that register and wait the second 8-bit slot for the register value reading, maybe not sending bits during the second 8-bit slots, as performed in the second and third lines of your first picture, and as described in the datasheet, p. 46.

loop (
MOSI 86h MISO 00h
MOSI 00h MISO 6Ah
)

You can also use multiple byte read command by adding blocks of 8 clock pulses to the previous one, but you will read consecutive registers and not only the WHO_AM_I in this way.

-Eleon

Eleon BORLINI
ST Employee

Ps: for a specific implementation of IMU sensor SPI communication implementation on STM32F1 MCU family you can browse the STM32CubeF1 function pack, that contains a few examples related to sensors.

-Eleon