cancel
Showing results for 
Search instead for 
Did you mean: 

Why am I getting garbage data reading from the LIS3DSH accelerometer with the STM32F407G MCU?

Jay Gaz
Associate II
Posted on June 12, 2018 at 00:02

The original post was too long to process during our migration. Please click on the attachment to read the original post.
8 REPLIES 8
AvaTar
Lead
Posted on June 12, 2018 at 09:48

However, now I only get 0xFF as the data when I debug the program.

I suspect this indicates the slave device is not answering at all.

Have you checked the lines with s acope ?

What board you working on ?

There are Discovery boards around where the connections to said accelerometer are set to I2C in hardware.

henry.dick
Senior II
Posted on June 14, 2018 at 00:28

Try software spi first. Once you get it going, switch to hardware spi.

Posted on June 13, 2018 at 23:50

Since I'm so new to the embedded world, I do not have a scope yet. I'll definitely do some research and buy an oscilloscope.

In the meantime, is there no other reliable way to detect whether the slave device is answering at all?

I'm using the STM32F407G-DISC1 board. And it's user manual definitely states that the accelerometer uses the SPI protocol. This is what the manual says:

The STM32F407VG microcontroller controls this motion sensor through the SPI interface.

This is on page 17 of DocID022256 Rev 6. So I think SPI should be fine.

Perhaps I should use the HAL driver functions first to see if the accelerometer is responding. If the works, at least I'll know that it's an issue with my code and setup of all the configurations. If it doesn't work, then I'm sure what to do at that point.

Posted on June 14, 2018 at 00:29

A logic analyzer is much more useful here.

Posted on June 14, 2018 at 01:22

double check phase and polarity against the timing in the data sheet

Posted on June 14, 2018 at 02:43

This is what the accelerometer's data sheet says:

SPC is the serial port clock and it is controlled by the SPI master. It is stopped high when CS is high (no transmission). SDI and SDO are respectively the serial port data input and output. Those lines are driven at the

falling edge of SPC and should be captured at the rising edge of SPC.

So based on this, I've set both the clock phase and clock polarity to 1. So I think I got these two right.

Posted on June 14, 2018 at 02:44

To be honest, I'm not sure what you mean by that.

Posted on June 15, 2018 at 07:42

The SPL-based firmware package for the F4 Discovery contains example code for the MEMS sensors (including the LIS3D), e.g. the demo application.

I would check the settings made there.