2024-04-17 07:43 PM - edited 2024-04-17 07:47 PM
HI All,
I am trying to connect an STM32F413 and the TDK ICM-42688 IMU chip using SPI. The connection works correctly and the ICM-42688 responds, but the data doesnt seem to be clocked into the STM32F413 chip.
The ICM-42688 Timing data is:
So CPOL = 1, CPHA = 2 and SCLK ic high in idle.
(I have also tried CPOL = 1 and CPHA = 1 which also delivers an identical result)
The Device Config is as follows:
hspi1.Instance = SPI1;
hspi1.Init.Mode = SPI_MODE_MASTER;
hspi1.Init.Direction = SPI_DIRECTION_2LINES;
hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
hspi1.Init.CLKPolarity = SPI_POLARITY_HIGH;
hspi1.Init.CLKPhase = SPI_PHASE_2EDGE;
hspi1.Init.NSS = SPI_NSS_SOFT;
hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_128;
hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
hspi1.Init.CRCPolynomial = 10;
I have it slowed down at present to see if speed is the cause of my problems...
When I monitor the lines with my Saleae 16 I get a good response.
The 0x76,00 is a write to the register 0x76 to select bank 0.
The 0xF5,00 is a read request for the Register 0x75 and it should return 0x47 which is is doing - YAY.
My problem is that the data doesnt seem to be clocked into the STM32F413 chip...
I always end up with 0x00.
I have tried a number of different permutations using HAL_SPI_Read and HAL_SPI_TransmitReceive and none seem to work.
Here is the code doing the work.
I am somewhat flumoxed at present.
Any and all thoughts are appeciated.
Thanks in Advance.
cheers
Paul
2024-04-17 07:46 PM
Sorry Typo . 0x75 is a register in Bank 0.
2024-06-19 10:46 PM
Hey can u share the code for the driver , I am currently working on a project and i need the drivers code very urgently
kindly share the libarary you used to interface the ICM-42688P
2024-06-20 12:58 AM - edited 2024-06-20 01:24 AM
Spi_TransmitReceive , you have to fill with the register value and then dummy bytes of zero to clock out the data. For example
rx[0] = 0x75; rx[1] = 0 till the len count.
FYI. As per datasheet, the first bit should be 1 for read and 0 for write. So you can try eith 0xF5
2024-06-20 02:57 AM
sir do you have the code for ICM42688 for interfacing with stm32 ?? if yes ,kindly share it.
2024-10-21 01:19 AM
Hi,speedyPLH.
Using the same parameter(except the baudrate->656.25KBits/s ) in my project that it seems working,you can try my code
void SPI2_TestFunction(void)
{
SPI2_CS_Enable();
SPI2_Send_buffer[0]= 0x76|WriteOperation;
HAL_SPI_TransmitReceive(&hspi2, &SPI2_Send_buffer[0], &SPI2_Recv_buffer[0], 2, 10);
SPI2_CS_Disable();
HAL_Delay(10);
SPI2_CS_Enable();
SPI2_Send_buffer[0]= 0x75|ReadOperation;
HAL_SPI_TransmitReceive(&hspi2, &SPI2_Send_buffer[0], &SPI2_Recv_buffer[0], 2, 10);
SPI2_CS_Disable();
}