cancel
Showing results for 
Search instead for 
Did you mean: 

Cannot communicate with LSM6DSV with SPI nor I2C

pansamic
Visitor

I designed a small PCB for LSM6DSV but I got no signal on SPI-MISO and got NACK on I2C-SDA.

I have replaced several chips but all the chips have the same behaviour(no signal reply).

I'm very sure the SPI and I2C pins are correctly connected to LSM6DSV.

(1)Custom PCB design

This is the PCB design of my custom board. All the net label are connected to pads on board. Never mind "LSM6DSOTR" in the schematic. Actually I soldered LSM6DSV on board since LSM6DSV has the same chip package with LSM6DSO.
VDDIO and VDD are 3.3V and this board shares the same ground with stm32.

pansamic_0-1741676602183.png

pansamic_1-1741676713794.png

(2)SPI communication issue
SPI_SCK and SPI_MOSI signal is correct but SPI_MISO has no signal.
I configured STM32H743XIH6 SPI in STM32CubeMX like this. No NVIC, no DMA.

pansamic_2-1741676995350.png

I implemented the SPI polling read/write function for official ST LSM6DSV driver code.

 

int32_t lsm6dsv_spi_read(void* handle, uint8_t reg, uint8_t *data, uint16_t len)
{
  reg |= 0x80;
  LL_SPI_SetTransferSize(handle, len+1);
  LL_SPI_Enable(handle);
  LL_SPI_StartMasterTransfer(handle);
  LL_GPIO_ResetOutputPin(SPI_CS_IMU_GPIO_Port, SPI_CS_IMU_Pin);
  while(!LL_SPI_IsActiveFlag_TXP(handle));
  LL_SPI_TransmitData8(handle, reg);
  while(!LL_SPI_IsActiveFlag_RXP(handle));
  data[0] = LL_SPI_ReceiveData8(handle);
  for(uint16_t i = 0; i < len; i++)
  {
    while(!LL_SPI_IsActiveFlag_TXP(handle));
    LL_SPI_TransmitData8(handle, 0x00);
    while(!LL_SPI_IsActiveFlag_RXP(handle));
    data[i] = LL_SPI_ReceiveData8(handle);
  }
  while (LL_SPI_IsActiveFlag_EOT(handle) == RESET);
  LL_GPIO_SetOutputPin(SPI_CS_IMU_GPIO_Port, SPI_CS_IMU_Pin);
  LL_SPI_ClearFlag_EOT(handle);
  LL_SPI_ClearFlag_TXTF(handle);
  LL_SPI_Disable(handle);
  return 0;
}
int32_t lsm6dsv_spi_write(void* handle, uint8_t reg, const uint8_t *data, uint16_t len)
{
  LL_SPI_SetTransferSize(handle, len+1);
  LL_SPI_Enable(handle);
  LL_SPI_StartMasterTransfer(handle);
  LL_GPIO_ResetOutputPin(SPI_CS_IMU_GPIO_Port, SPI_CS_IMU_Pin);
  while(!LL_SPI_IsActiveFlag_TXP(handle));
  LL_SPI_TransmitData8(handle, reg);
  for(uint16_t i = 0; i < len; i++)
  {
    while(!LL_SPI_IsActiveFlag_TXP(handle));
    LL_SPI_TransmitData8(handle, data[i]);
  }
  while (LL_SPI_IsActiveFlag_EOT(handle) == RESET);
  LL_GPIO_SetOutputPin(SPI_CS_IMU_GPIO_Port, SPI_CS_IMU_Pin);
  LL_SPI_ClearFlag_EOT(handle);
  LL_SPI_ClearFlag_TXTF(handle);
  LL_SPI_Disable(handle);
  return 0;
}

 

The main function read ID continously.

 

/**
  * @brief  The application entry point.
  * @retval int
  */
int main(void)
{

  /* USER CODE BEGIN 1 */
  stmdev_ctx_t dev_ctx = {
    .write_reg = lsm6dsv_spi_write,
    .read_reg = lsm6dsv_spi_read,
    .mdelay = LL_mDelay,
    .handle = SPI1
  };
  uint8_t data;
  /* USER CODE END 1 */

  /* MPU Configuration--------------------------------------------------------*/
  MPU_Config();

  /* MCU Configuration--------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  LL_APB4_GRP1_EnableClock(LL_APB4_GRP1_PERIPH_SYSCFG);

  /* System interrupt init*/
  NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_4);

  /* SysTick_IRQn interrupt configuration */
  NVIC_SetPriority(SysTick_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(),15, 0));

  /* USER CODE BEGIN Init */

  /* USER CODE END Init */

  /* Configure the system clock */
  SystemClock_Config();

  /* USER CODE BEGIN SysInit */

  /* USER CODE END SysInit */

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_SPI1_Init();
  /* USER CODE BEGIN 2 */
  lsm6dsv_spi_mode_set(&dev_ctx, LSM6DSV_SPI_4_WIRE);
  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
    /* Use official driver code to read ID */
    lsm6dsv_device_id_get(&dev_ctx, &data);
    LL_mDelay(1);
    /* USER CODE END WHILE */

    /* USER CODE BEGIN 3 */
  }
  /* USER CODE END 3 */
}

 

The following picture is SPI communication to read LSM6DSV's ID. SCK(yellow), MOSI(blue), MISO(purple), CS(green). The MISO line has no signal.
IMG_20250311_153603.jpg

I tried HAL library but I got no signal on MISO either.

(3)I2C communication issue

I got NACK signal from LSM6DSV and the I2C communication was stopped after sending the I2C slave address.

I connect SDO pin to GND so the slave address should be 0b1101010(7-bit address) according to LSM6DSV datasheet.

STM32CubeMX configuration. No NVIC, no DMA.

pansamic_3-1741677013647.png

I2C read/write function for official ST LSM6DSV driver code.

 

int32_t lsm6dsv_i2c_read(void* handle, uint8_t reg, uint8_t *data, uint16_t len)
{
  while(LL_I2C_IsActiveFlag_BUSY(I2C1));
  LL_I2C_HandleTransfer(I2C1, 0xD4, LL_I2C_ADDRSLAVE_7BIT, 1, LL_I2C_MODE_SOFTEND, LL_I2C_GENERATE_START_WRITE);
  while(!LL_I2C_IsActiveFlag_TXIS(I2C1));
  LL_I2C_TransmitData8(I2C1, reg);
  while(!LL_I2C_IsActiveFlag_TC(I2C1));
  LL_I2C_HandleTransfer(I2C1, 0xD4, LL_I2C_ADDRSLAVE_7BIT, len, LL_I2C_MODE_AUTOEND, LL_I2C_GENERATE_RESTART_7BIT_READ);
  for(uint8_t i=0 ; i<len ; i++)
  {
      while(!LL_I2C_IsActiveFlag_RXNE(I2C1));
      data[i] = LL_I2C_ReceiveData8(I2C1);
  }
  while(!LL_I2C_IsActiveFlag_STOP(I2C1));
  LL_I2C_ClearFlag_STOP(I2C1);
  return 0;
}
int32_t lsm6dsv_i2c_write(void* handle, uint8_t reg, const uint8_t *data, uint16_t len)
{
  while(LL_I2C_IsActiveFlag_BUSY(I2C1));
  LL_I2C_HandleTransfer(I2C1, 0xD4, LL_I2C_ADDRSLAVE_7BIT, len+1, LL_I2C_MODE_AUTOEND, LL_I2C_GENERATE_START_WRITE);
  while(!LL_I2C_IsActiveFlag_TXIS(I2C1));
  LL_I2C_TransmitData8(I2C1, reg);
  for(uint8_t i=0 ; i<len ; i++)
  {
      while(!LL_I2C_IsActiveFlag_TXIS(I2C1));
      LL_I2C_TransmitData8(I2C1, data[i]);
  }
  while(!LL_I2C_IsActiveFlag_STOP(I2C1));
  LL_I2C_ClearFlag_STOP(I2C1);
  return 0;
}

 

The signal of I2C communication to read LSM6DSV's ID but got NACK after sending slave address. I used STM32H7 development board so there is no pull up register on SCL and SDA.2ef19391-ae28-41a5-9e11-0bb3d1bd6a06.jpeg

0 REPLIES 0