cancel
Showing results for 
Search instead for 
Did you mean: 

Reading ASM330LHHX sensor using SPI

SJin.4
Associate II

Hi, I'm trying to get sensor data using the SPI protocol, but it seems not to be working as it should be.

Developing environments are: S32 Design Studio for Power Architecture, MPC5748G, ASM330LHHX, dspi_driver example code

At first, I sent a read request for WHO_AM_I address 0x8F then the data sequence returned.

But still, the same data sequence returned which was not what I wanted(0x6b).

So I changed the request address to 9A and some others, but still, the same data sequence returned.


_legacyfs_online_stmicro_images_0693W00000bk4MaQAI.png
_legacyfs_online_stmicro_images_0693W00000bk4MfQAI.pngThe pictures above are who_am_i return data.

The data sequence is " 0x00 ... 0xD6 .... 0x00 ... 0x08 .... 0x00... 0x01 ... 0x00 ... 0xC0..."

This is how I configure the SPI component :


_legacyfs_online_stmicro_images_0693W00000bk4M1QAI.png
_legacyfs_online_stmicro_images_0693W00000bk4MBQAY.pngWhat is the correct way to read and write sensor data? Is there a guide for this?

Thanks in advance.

4 REPLIES 4
Federica Bossi
ST Employee

Hi @SJin.4​ ,

Welcome to ST Community!

Looking at your code and oscilloscope acquisitions I don't see the CS. Are you setting it?

If you want a guide you can look at our examples on Github at this link.

In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.
SJin.4
Associate II

Hi, thanks for the reply.

In S32 Design Studio, CS seems to be called SS. So, I set CS as active low, starting from high(1) and turning to low(0) when it runs.


_legacyfs_online_stmicro_images_0693W00000bkKJkQAM.png
_legacyfs_online_stmicro_images_0693W00000bkKGNQA2.pngthen it turns to low again.

Thanks for the GitHub link, but I've already tried this example a few times.

And the MCU I use is not NUCLEO_F411RE, STEVAL_MKI109V3, or neither SPC584B_DIS, I think that's why the example didn't work on MPC5748G.

Right now, I'm just trying to get the default data(0x6B) from the WHOAMI register(0x0F).

here's the test:

1. initialize the spi master using the configuration above, tx buffer[2] and RX buffer[2]


_legacyfs_online_stmicro_images_0693W00000bkKXAQA2.png2. then start transfer using the SPI master transfer function with frame number 4


_legacyfs_online_stmicro_images_0693W00000bkKZVQA2.png3. first and second outcomes


_legacyfs_online_stmicro_images_0693W00000bkKdNQAU.png
_legacyfs_online_stmicro_images_0693W00000bkKbmQAE.png 

4. and till 7th, it's all 0x00 and 0x37


_legacyfs_online_stmicro_images_0693W00000bkKgRQAU.png 

5. on 16th turn it's 0x6b


_legacyfs_online_stmicro_images_0693W00000bkKhtQAE.png 

but in my understanding, 0x6b should come out right after we tx 0x8f.

Am I doing something wrong? or is there more to do for sensor configuration?

Thanks,

Federica Bossi
ST Employee

Ciao @SJin.4​ ,

From the code you linked I'm not able to see if you are using SPI4w or SPI3w. If you are using SPI3w, before reading you need to set the SIM bit (Write in reg12h 06h).

Otherwise, in SP4, can you send me a complete acquisition with SDO-SDA-SCL-CS Lines?

In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.
SJin.4
Associate II

Hi, @Federica Bossi​ 

It's SPI4w that I'm using right now.

But I'm not allowed to post an acquisition, it's owned by the company.

So would it be okay for me to send you an acquisition via email?

If it's okay, please leave me your email address.

Thanks a lot,

BR