0

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?

  • The workaround should only be needed on initialization, and the busy flag error should not happen at runtime, unless you have something weird going on in the hardware or using the HAL in a non-intended way. Have you debugged or otherwise determined why it returns HAL_BUSY, because it does not neccessarily mean the I2C peripheral has BUSY flag set, but the HAL is busy, if for example the I2C transaction failed due to EEPROM not responding with ACK because it can be busy writing the previously sent data. Post schematics and full code where you call that. So it needs proper error state handling. – Justme Dec 16 '20 at 07:54
  • I'm saying that if it's ONLY HAL BUSY flag, is it proper way to handle BUSY flag? – user3473485 Dec 16 '20 at 08:09
  • DURING INITIALIZATION. – user3473485 Dec 16 '20 at 08:17

0 Answers0