LSM303AGR SPI Read Problem
Hi
I have lsm303agr mems sensor with stm32g4. It uses 3 wire SPI mode. I have problem with SPI communication. I used CubeMX with HAL mode and STMems_Standard_C_drivers for lsm303. The problem is that, when i read whoami register it reads 0x33 which is correct. But the next time i read as 0. Next time again 0x33 and so on. It reads 0x33 and 0 sequentially. SPI times out. I have seen HAL examples written only for Full duplex communication. So, i used CubeMX with SPI in half duplex mode to generate the project. This is my code snippet:
while(1)
{
HAL_GPIO_WritePin(GPIO_Sensor, CS_Sensor_Pin, GPIO_PIN_RESET);
HAL_Delay(1);
HAL_SPI_Transmit(&hspi1, &whoami_addr, 1, 1000);
HAL_SPI_Receive(&hspi1, &whoami_val, 1, 1000);
HAL_Delay(1);
HAL_GPIO_WritePin(GPIOA_Sensor CS_Sensor_Pin, GPIO_PIN_SET);
}
Am i missing something with SPI 3-Wire mode?
Best regards.
