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.
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?
Solved! Go to Solution.
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
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
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 :
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)?
2. What's different between SPI_MasterTransfer and +Blocking except for timeout?
Thanks, I'm really new to this so please bear with me.
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