Showing results for 
Search instead for 
Did you mean: 

accelerometer LIS2DH12 strange and wrong behavior on SPI BUS (I2C is okay)

Associate II

I have an accelerometer LIS2DH12 connected to my STM32 with I2C and it works fine. Now I changed to SPI bus and somehow the accelerometer behaves strange. I can set parameters like "full scale to 2g" and "set Output Data Rate to 1Hz" and also read out values correctly.

But when I run the system afterwards the frequency is much higher and also the values are not correct.

I use the STMicroelectronics/STMems_Standard_C_drivers from GitHub and the examples "lis2dh12_self_test". I have already tested the 3 and 4 wire mode for SPI, But both behave the same, when I set or write the parameters everything is ok, also the LIS2DH12_ID reads correctly but the values and also the frequency of the readout is wrong, check if new value available does not seem to be correct. The same code works well with I2C though,

I have only adjusted the functions "platform_read" and "platform_write".

The CS I switch as in the examples also in the "platform_read" and "platform_write" function manually with a GPIO pin. As in the examples.

What am I doing wrong???

Thanks for your help