I use the STM32F29 and have a similiar problem with the I2C as the following User:
The i2C works but sometimes when i use "HAL_I2C_Mem_Read" there is a timeout error.
After this timeout often the I2C no longer works because of a busy error.
When i measure SDA und the SCL I see that SDA is low and SCL is always high without a clock.
Why this error hapens and what can i do?
In the link above the solution is to make a stop signal with following code when the I2C is busy:
I2C_WaitOnFlagUntilTimeout(&hi2c1, I2C_FLAG_BUSY, SET, 1000);
When i call that code the busy error persists.
When i measure SDA und SCL at the Busy error and after that code there are different states.
Sometimes SCL and SDA are still low. But sometimes after I have made a hardware reset and try to repeat it, SDA is low and SCL is high or they are both high.
while (HAL_I2C_GetState(&hi2c1) != HAL_I2C_STATE_READY);
test = HAL_I2C_Mem_Read(&hi2c1, panel_touch_adresse, adresse_anpassen(mxt_object_message_count_t44.start_address), I2C_MEMADD_SIZE_16BIT, (uint8_t *)buffer, mxt_object_message_count_t44.size_minus_one +1, 100);
if(test == HAL_ERROR)
HAL_GPIO_WritePin(GPIOG, GPIO_PIN_7, RESET);
if(test == HAL_BUSY)
I2C_WaitOnFlagUntilTimeout(&hi2c1, I2C_FLAG_BUSY, SET, 1000,HAL_GetTick());
if(test == HAL_TIMEOUT)
if (zaehler >=2) test = HAL_OK;
}while(test != HAL_OK);