cancel
Showing results for 
Search instead for 
Did you mean: 

when exactly void HAL_I2C_ErrorCallback(I2C_HandleTypeDef *hi2c) will be triggered and i have enabled the error interrupt in IOC setting but i could not understand occasion of this happening .

MMARI.1
Senior

HAL_I2C_IsDeviceReady is good option to check sensor presence but while i2c sensor working incase of error occurrence will error interrupt will be triggered ?

This discussion is locked. Please start a new topic to ask your question.
1 ACCEPTED SOLUTION

Accepted Solutions
Foued_KH
ST Employee

Hello @MMARI.1​ ,

Try to get the error in the void HAL_I2C_ErrorCallback(I2C_HandleTypeDef *hi2c) :

  if (HAL_I2C_GetError(I2cHandle) != HAL_I2C_ERROR_AF)
  {
    Error_Handler();
  }

Error_Handler() function is called when error occurs:

   1- When Slave don't acknowledge it's address, Master restarts communication.

   2- When Master don't acknowledge the last data transferred, Slave don't care in this example.

Foued

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

View solution in original post

1 REPLY 1
Foued_KH
ST Employee

Hello @MMARI.1​ ,

Try to get the error in the void HAL_I2C_ErrorCallback(I2C_HandleTypeDef *hi2c) :

  if (HAL_I2C_GetError(I2cHandle) != HAL_I2C_ERROR_AF)
  {
    Error_Handler();
  }

Error_Handler() function is called when error occurs:

   1- When Slave don't acknowledge it's address, Master restarts communication.

   2- When Master don't acknowledge the last data transferred, Slave don't care in this example.

Foued

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.