1

I use an STM32H743ZIT6 to communicate with an LMP92066 temperature sensor.

When I call HAL_I2C_IsDeviceReady() method to find Slave Address, it goes into an infinite while loop in the method and does not return anything.

HAL_I2C_IsDeviceReady() method includes the following loop. This loop is infinite because tmp1 and tmp2 are always RESET.

while ((tmp1 == RESET) && (tmp2 == RESET))
      {
        if (Timeout != HAL_MAX_DELAY)
        {
          if (((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0U))
          {
            /* Update I2C state */
            hi2c->State = HAL_I2C_STATE_READY;

            /* Update I2C error code */
            hi2c->ErrorCode |= HAL_I2C_ERROR_TIMEOUT;

            /* Process Unlocked */
            __HAL_UNLOCK(hi2c);

            return HAL_ERROR;
          }
        }

        tmp1 = __HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_STOPF);
        tmp2 = __HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_AF);
      }

I have tried using I2C2, I2C3, I2C4 instead of I2C1 and it does not work.

I have used __HAL_RCC_I2C1_CLK_ENABLE(); before calling method but it does not work too.

pmacfarlane
  • 3,057
  • 1
  • 7
  • 24
  • Have you got the clock phase and polarity correct? There are only 4 possible combinations to try, might as well try them all. – pmacfarlane Jul 19 '23 at 13:29
  • Also note that you have to shift the device address left one bit. And note that it does not have to be an infinite loop, you can specify a timeout in milliseconds. – pmacfarlane Jul 19 '23 at 13:31
  • It seems like the loop waits for either Arbitration loss flag or Stop bit flag to declare the bus "available". I guess a way out of the loop is to have a stop bit flag set. But if your I2C is interrupt-driven (not blocking), it may require small adjustments in how and where interrupts are triggered and flags are cleared. – Ilya Jul 20 '23 at 08:48

0 Answers0