Skip to main content
MMARI.1
Senior II
February 20, 2023
Solved

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 .

  • February 20, 2023
  • 1 reply
  • 920 views

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 topic has been closed for replies.
Best answer by Foued_KH

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

1 reply

Foued_KH
Foued_KHBest answer
ST Employee
February 20, 2023

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.