2023-05-15 01:06 AM - edited 2023-11-20 05:29 AM
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.
The 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 :
What is the correct way to read and write sensor data? Is there a guide for this?
Thanks in advance.
2023-05-17 02:07 AM
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.
2023-05-17 07:28 PM - edited 2023-11-20 05:30 AM
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.
then 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]
2. then start transfer using the SPI master transfer function with frame number 4
3. first and second outcomes
4. and till 7th, it's all 0x00 and 0x37
5. on 16th turn it's 0x6b
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,
2023-05-18 02:33 AM
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?
2023-05-18 04:37 PM
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