0
\$\begingroup\$

I need to read temparature and rh values from sht35 sensor. here is the datasheet

I am using stm32f0 and I have 2 different sensor. problem keep occurs with both sensor. Address pin connected to the ground so i2c address must be 0x44 but my code stucks at the while loop below. I am using keil, and cubemx to generate configurations. I watch sda and scl lines with a scope and everything looks right.what could be the possible problem of failure? ps: I tried checking out of the while loop too, nothing changed.

while(HAL_I2C_IsDeviceReady(&hi2c1, 0x44, 2, 100) != HAL_OK);

my i2c init function is here

static void MX_I2C1_Init(void)
{

  /* USER CODE BEGIN I2C1_Init 0 */

  /* USER CODE END I2C1_Init 0 */

  /* USER CODE BEGIN I2C1_Init 1 */

  /* USER CODE END I2C1_Init 1 */
  hi2c1.Instance = I2C1;
  hi2c1.Init.Timing = 0x2000090E;
  hi2c1.Init.OwnAddress1 = 0;
  hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
  hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
  hi2c1.Init.OwnAddress2 = 0;
  hi2c1.Init.OwnAddress2Masks = I2C_OA2_NOMASK;
  hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
  hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
  if (HAL_I2C_Init(&hi2c1) != HAL_OK)
  {
    Error_Handler();
  }
  /** Configure Analogue filter 
  */
  if (HAL_I2CEx_ConfigAnalogFilter(&hi2c1, I2C_ANALOGFILTER_ENABLE) != HAL_OK)
  {
    Error_Handler();
  }
  /** Configure Digital filter 
  */
  if (HAL_I2CEx_ConfigDigitalFilter(&hi2c1, 0) != HAL_OK)
  {
    Error_Handler();
  }
  /* USER CODE BEGIN I2C1_Init 2 */

  /* USER CODE END I2C1_Init 2 */

}

edit:

HAL_I2C_IsDeviceReady(&hi2c1, 0x44, 2, 100)

waits for an ACK signal from i2c bus, I can't see any ACK on scope too.

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

You are using the wrong address. 0x44 in 7-bit notation is used in datasheet, so in 8-bit notation used by STM32 it should be 0x88.

\$\endgroup\$
1
  • \$\begingroup\$ of course, that's documented in hal library. thanks, worked. \$\endgroup\$
    – sinany1
    Oct 25, 2019 at 10:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.