I'm using HAL to use I2C and somemtimes I'm getting HAL_BUSY flag, I read STM32F103 errata and added BUSY flag clear according this, i2c busy flag clear
But I changed error handling little bit and is it right?
do
{
status = HAL_I2C_Mem_Write(eeprom_handler.instance, (uint16_t)device_address, mem_addr_masked,
I2C_MEMADD_SIZE_8BIT, src, bytes_to_write, 1000);
if (HAL_OK == status)
{
bytes_written = bytes_to_write;
}
else if (HAL_BUSY == status)
{
I2C_ClearBusyFlagErratum(&eeprom_handler, 1000);
}
else // if HAL_ERROR, or HAL_TIEMOUT
{
return;
}
}
while(status != S_OK);
in other words, try to write until status will be HAL_OK, because without do while
loop, the write procedure will be skipped.
So is this do while
loop the correct way to handle Write/Read functions?