Question
Read/Write to external EEPROM fails sometimes .What might be issue ?
Hi,
I am using STM32L07XXX
I am reading/writing and external eeprom using I2C
" but I2C communication fails many time ". and system hangs
Does this function run needs to be atomic ?
But using __disable_irq and __enable_irq effects HAL_GetTick() ?
Can i enable only HAL_GetTick() ?
Or any other issue causing this ?
Following is code for writing to eeprom:
void write_eeprom_float(int mem_addr,float pdata, int size_write)
{
uint32_t time_start ;
time_start = HAL_GetTick();
while (HAL_I2C_GetState(&hi2c3) != HAL_I2C_STATE_READY)
{
if((HAL_GetTick() - time_start) > 500)
break;
}
/* Check if the EEPROM is ready for a new operation */
time_start = HAL_GetTick();
while (HAL_I2C_IsDeviceReady(&hi2c3, EEPROM_ADDRESS, EEPROM_MAX_TRIALS, I2C_XFER_TIMEOUT_MAX) == HAL_TIMEOUT)
{
if((HAL_GetTick() - time_start) > 500)
break;
}
/* Wait for the end of the transfer */
time_start = HAL_GetTick();
while (HAL_I2C_GetState(&hi2c3) != HAL_I2C_STATE_READY)
{
if((HAL_GetTick() - time_start) > 500)
break;
}
if(HAL_I2C_Mem_Write(&hi2c3 , (uint16_t)EEPROM_ADDRESS,(uint16_t)mem_addr , I2C_MEMADD_SIZE_8BIT, (uint8_t *)&pdata, sizeof(pdata),1000)!= HAL_OK)
{
error_number = I2C_controller_EEPROM ;
/* Writing process Error */
Error_Handler();
}
time_start = HAL_GetTick();
while (HAL_I2C_GetState(&hi2c3) != HAL_I2C_STATE_READY)
{
if((HAL_GetTick() - time_start) > 500)
break;
}
/* Check if the EEPROM is ready for a new operation */
time_start = HAL_GetTick();
while (HAL_I2C_IsDeviceReady(&hi2c3, EEPROM_ADDRESS, EEPROM_MAX_TRIALS, I2C_XFER_TIMEOUT_MAX) == HAL_TIMEOUT)
{
if((HAL_GetTick() - time_start) > 500)
break;
}
/* Wait for the end of the transfer */
time_start = HAL_GetTick();
while (HAL_I2C_GetState(&hi2c3) != HAL_I2C_STATE_READY)
{
if((HAL_GetTick() - time_start) > 500)
break;
}
}