I'm programming the Atmega64M1. The access on the EEPROM is described in the datasheet, and I have no issues writing it or reading it. In the datasheet it is said to wait for completing of previous write before reading or writing the eeprom :
{
/* Wait for completion of previous write */
while(EECR & (1<<EEPE))
;
/* Set up address and Data Registers */
EEAR = uiAddress;
EEDR = ucData;
/* Write logical one to EEMPE */
EECR |= (1<<EEMPE);
/* Start eeprom write by setting EEPE */
EECR |= (1<<EEPE);
}
My question is : is there a chance that the while loop doesn't stop ? The EEPE bit is supposed to be cleared by hardware, but is it a good practice to add a software verification to make sure that we eventually exit the loop ? Something like:
int i = 0;
/* Wait for completion of previous write */
while((EECR & (1<<EEPE)) && (i < 100))
{
i++;
}