ICM42688 - P COMMUNICATION using SPI

By vasudevrk321gmailcom , 3 October 2023

I Am unable to communicate with ICM42688 - P sensor using SPI.
I tried to read WHOAMI register and it's supposed to give some value but it's returning 0x00.

I have attached a code for receive and transmit, please suggest me some way around to solve this problem

mustafayildiri…

2 years 5 months ago

Hello,

You can check out our driver to have a better understanding of how its setup to work with SPI

It is located here: https://invensense.tdk.com/developers/software-downloads/#smartmotion
Download the file named: DK-42688-P SmartMotion eMD 2.0.9 (Updated 2023.04.03)

phpbb Post ID
45252

vasudevrk321gmailcom

2 years 5 months ago

Hello,

I am not using the Development Kit for ICM 42688-P will the driver be still useful for me?

Thanks

phpbb Post ID
45256

mustafayildiri…

2 years 5 months ago

Hi,

Driver is for SAMG55 Atmel MCU, but it has example code that help you solve your problem. Please check out the DS and application notes as well.

https://invensense.tdk.com/products/motion-tracking/6-axis/icm-42688-p/

phpbb Post ID
45262

dharanitmistra…

2 years 4 months ago

Hi,

1. We checked the above example code. But, we are not getting the Correct SPI Mode and typical clock frequency to communicate with ICM42866-P through STML412 MCU.
By referring the IMU datasheet, we tried with Motorola mode (NSS - Enabled, Clock Polarity - 1, Clock phase - 1(sampling at rising edge)) to read the WHOAMI register value through MCU with 1MHz clock frequency.
But, we are not receiving the expected value of WHOAMI register instead we are getting 0x00 value.
Could you please confirm the mode and typical clock frequency in which ICM42688-P's SPI interface operates?

2. And with the above code attached by @vasudevrk321gmailcom, there is some delay between transmit 8 clock cycles(WHOAMI register address) and receive 8 clock cycles(reading WHOAMI value). So, we used transreceive function to read the data with 16 continuous clock cycles as recommended in datasheet ("SPI read operations are completed in 16 or more clock cycles (two or more bytes)) and it doesn't works.
Could you please suggest, if any change is needed on the attached code?

Thanks

phpbb Post ID
45286

mustafayildiri…

2 years 4 months ago

Hello,

Unfortunately, I cannot suggest any edits on the attached code since I am not familiar with the MCU and the environment you are using the IMU in. Please try to develop your code based on guidelines provided by the datasheet, application note, and the eMD example code provided.

phpbb Post ID
45317

altinellergmailcom

2 years 4 months ago

Hello All,

I wrote my own driver for and arm cortex m4 class mcu, that works over spi.

One thing I noticed is that in order to receive from spi, ***in some platforms*** you have to transmit data to receive data from spi.

Here is an example:

void read_byte(uint8_t address, uint8_t *data) {

MAP_GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_3, 0x00); // CS low

MAP_SSIDataPut(SSI0_BASE, address | 0x80); // send address, read operation
MAP_SSIDataGet(SSI0_BASE, &spi_byte_buffer[0]); // receive blank

MAP_SSIDataPut(SSI0_BASE, 0x00); // send blank
MAP_SSIDataGet(SSI0_BASE, &spi_byte_buffer[0]); // read data

while(MAP_SSIBusy(SSI0_BASE)); // wait for transaction to finish
MAP_GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_3, GPIO_PIN_3); // CS high
while(MAP_SSIDataGetNonBlocking(SSI0_BASE, &spi_byte_buffer[0])); // empty buffer

data[0] = spi_byte_buffer[0] & 0xFF; // return data

}

So for each DataGet, you need to DataPut before, and vice-versa while writing.

This was a stopper for my driver until i figured it out.

Hope this helps,

Best Regards,
Can Altineller

phpbb Post ID
45356

mustafayildiri…

2 years 4 months ago

Thank you for your contribution!

phpbb Post ID
45361
phpbb Topic ID
45250