2023-04-17 06:05 AM
I'm using i2c interface to communicate with a eeprom memory, by dma.
It's working, however, when I put a wrong address to write in the memory (to test the errors), I get as return HAL_ERROR, but the function HAL_I2C_ErrorCallback (that i implemented) does not called.
How can I get a callback from this function in a error situation?
Part of my code is available below:
status = HAL_I2C_Mem_Write(&hi2c3, 0xB4, (0<<8), 2, dataWrite, 270, 1000); //Wrong Address
void HAL_I2C_ErrorCallback(I2C_HandleTypeDef *hi2c){
HAL_UART_Transmit(&huart1, errorMsg, sizeof(errorMsg), 1000);
}
Solved! Go to Solution.
2023-04-17 06:57 AM
Hello @Ade J.3 ,
You can try to set this function :
/* USER CODE BEGIN 2 */
if (HAL_I2C_Mem_Write(&hi2c3, 0xB4, (0<<8), 2, dataWrite, 270, 1000) != HAL_OK)
{
Error_Handler();
}
/* USER CODE END 2 */
and :
/* USER CODE BEGIN 4 */
void HAL_I2C_ErrorCallback(I2C_HandleTypeDef *hi2c)
{
HAL_UART_Transmit(&huart1, errorMsg, sizeof(errorMsg), 1000);
}
/* USER CODE END 4 */
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.
2023-04-17 06:57 AM
Hello @Ade J.3 ,
You can try to set this function :
/* USER CODE BEGIN 2 */
if (HAL_I2C_Mem_Write(&hi2c3, 0xB4, (0<<8), 2, dataWrite, 270, 1000) != HAL_OK)
{
Error_Handler();
}
/* USER CODE END 2 */
and :
/* USER CODE BEGIN 4 */
void HAL_I2C_ErrorCallback(I2C_HandleTypeDef *hi2c)
{
HAL_UART_Transmit(&huart1, errorMsg, sizeof(errorMsg), 1000);
}
/* USER CODE END 4 */
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.
2023-04-18 05:27 AM
Thank you for the answer. That worked for me!
However, it isn't using DMA. Is there any way to get the callback with transmission by DMA?
2023-04-18 05:51 AM
If this solves your problem, please mark my answer as "Best Answer" by clicking on the "Select as Best" button, this can be helpful for Community users to find this solution faster.
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.
2023-04-18 06:07 AM
Yes you can get callback with transmission by DMA and by IT also.
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.
2023-04-20 05:48 AM
But the problem is I've have not been getting the callback with transmission by DMA, just by IT. Should I configure something different to get a correct functioning?
2023-04-20 07:05 AM
I recommend you this wiki : Getting started with I2C - stm32mcu
check the 2.3.3 NVIC or DMA settings↑ section.
You can check the available example in the STM32 cube FW .
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.