Skip to main content
blian.1
Visitor II
December 18, 2020
Question

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?

0693W000006GDxWQAW.png0693W000006GDxRQAW.png0693W000006GDxMQAW.png0693W000006GDxHQAW.png

This topic has been closed for replies.

2 replies

Eleon BORLINI
ST Employee
December 21, 2020

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
December 21, 2020

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