STM32 I2C HAL_I2C_IsDeviceReady() infinite loop problem

426 Views Asked by At

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.

0

There are 0 best solutions below