2
\$\begingroup\$

I have here a Problem with an I2C bus configuration, that runs in a timeout after a certain time. The I2C slave is a fujikura ap4/ag4 pressure sensor and the master a STM32F4. I read continiously the pressure and after around 5-10min, a timeout error occures and the HAL_I2C_Master_Receive always returns a timeout error after that. The error occures in the stm32f4xx_hal_i2c.c because the following routine falls into a HAL_TIMEOUT

   /* Wait until ADDR flag is set */
  if(I2C_WaitOnMasterAddressFlagUntilTimeout(hi2c, I2C_FLAG_ADDR, Timeout, Tickstart) != HAL_OK)
  {
    if(hi2c->ErrorCode == HAL_I2C_ERROR_AF)
    {
      return HAL_ERROR;
    }
    else
    {
      return HAL_TIMEOUT;
    }
  }

Edit: What I noticed is, that the I2C3->CR1->STOP is set before the HAL_I2C_Master_Receive call when it returns an error. When I then clear this flag a few times while debugging, the I2C recovers and runs then again, until the next, same error occurs.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ It is very annoying if you throw up a new question every minute. Please try all the things that you can do, then ask here the question! And it would be helpful if you provide your code also, it seems you are not clearing some flag correctly after reading the data. \$\endgroup\$
    – charansai
    Jan 29, 2018 at 12:17
  • \$\begingroup\$ Have you tried multiple devices or is it just this one that stops responding? \$\endgroup\$
    – stark
    Jan 29, 2018 at 12:17

1 Answer 1

3
\$\begingroup\$

I have witnessed this on other STM32 devices I have used. The basic issue is that in some cases there is a read-modify-write operation to I2C control register which ends up setting STOP and START bits simultaneously. ST HAL has had similar bugs for years, it is not 100% reliable, and must be fixed by accessing the I2C peripheral registers correctly in every situation (according to Reference Manual and Errata). This error gets triggered more often if there is other stuff happening as well (interrupts at critical moment or other tasks running under RTOS). They never seem to get it right, and each time they make changes to fix something, it works a bit differently, but it is never completetly fixed. For this reason it's best to make your own I2C handling code that fits your needs, even if it means to use the existing HAL as a base for your modifications.

\$\endgroup\$

Your Answer

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

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