Reading ASM330LHHX sensor using SPI

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Reading ASM330LHHX sensor using SPI

Jump to solution
1,134 Views
AhpKim
Contributor I

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.

https://community.nxp.com/t5/S32K/S32K148-LPSPI-unexpected-data/m-p/1209756

then I followed the link above, 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.

return.png

scope_22.png

The pictures above are who_am_i return data.

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

 

What is the correct way to read and write sensor data? Is there a guide for this?

 

0 Kudos
Reply
1 Solution
1,056 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

1) use "Active low" for clock polarity setting
2) both functions configure driver to start sending defined number of bytes, non-blocking function ends after this and you should test for end of transfer before it can be again called, for example by using DSPI_GetTransferStatus function.  Blocking transfer function does not finish until all defined number of bytes are sent or timeout expires.

BR, Petr

View solution in original post

0 Kudos
Reply
3 Replies
1,116 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

SPI protocol is given in device datasheet. Both the read register and write register commands are completed in 16 clock pulses or in multiples of 8 in case of multiple read/write bytes. 
So write/read at least 2 bytes with continuous PCS selection. 
If using non-blocking function you should test for end of transfer, for example by using DSPI_GetTransferStatus function, or use blocking transfer function; DSPI_MasterTransferBlocking

BR, Petr

0 Kudos
Reply
1,075 Views
AhpKim
Contributor I

Thanks for the reply,

I'm still a bit confused here.

I tried to write/read at 4 bytes with continuous PCS selection (Continous SS), but it didn't give any output. It says STATUS_BUSY. 

So this is how I configure the SPI component :

AhpKim_0-1683528321594.png

Now, I'm getting 6b occasionally, but the clock starts from 0(low).

========================================================================

So questions are these,

1. How should I configure it to have SPI timing mode 3 which makes the clock start from 1(high)? 

AhpKim_1-1683528465077.png

2. What's different between SPI_MasterTransfer and +Blocking except for timeout? 

AhpKim_2-1683528615669.png

 

Thanks, I'm really new to this so please bear with me.

 

0 Kudos
Reply
1,057 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

1) use "Active low" for clock polarity setting
2) both functions configure driver to start sending defined number of bytes, non-blocking function ends after this and you should test for end of transfer before it can be again called, for example by using DSPI_GetTransferStatus function.  Blocking transfer function does not finish until all defined number of bytes are sent or timeout expires.

BR, Petr

0 Kudos
Reply