AnsweredAssumed Answered

MQX 4.1.1 I2C->EEPROM

Question asked by Joseph Chen on Nov 3, 2014
Latest reply on Mar 5, 2015 by Jianwu Tong

I try to use MK70 to control an EEPROM via I2C Interface. I use the MQX I2C sample code. The code below is how it polls in i2c_write_eeprom() function.

 

      /* Wait for EEPROM write cycle finish - acknowledge */

      result = 0;

      do

      {  /* Sends just I2C bus address, returns acknowledge bit and stops */

         fwrite (&result, 1, 0, fd);

        

         if (I2C_OK != ioctl (fd, IO_IOCTL_FLUSH_OUTPUT, &param))

         {

            printf ("  ERROR during wait (flush)\n");

         }

        

         if (I2C_OK != ioctl (fd, IO_IOCTL_I2C_STOP, NULL))

         {

            printf ("  ERROR during wait (stop)\n");

         }

         result++;

         printf("param:%d", param);

      } while ((param & 1) || (result >= 1));

 

It will fail if I use i2c_read_eeprom() function immediately after i2c_write_eeprom() function. The terminal shows "Write to address 0x001a ... ERROR". However, if I add _time_delay(1) at the bottom of i2c_write_eeprom(), then the i2c_read_eeprom() will work successfully. Is there any solution to check whether EEPROM write cycle is finished since I don't want to use _time_delay()? Like check the flag or something else.

Outcomes