5 Replies Latest reply on Apr 8, 2017 7:12 AM by user_1377889

    Serial EEPROM (I2C based) writes/reads only first time..

    arun.john

       Hi,

         

      I am using the CY8CKIT-049-42XX prototype board for my experiments. I am trying to interface  a I2C based EEPROM 24LC256 to the board. The SDA pin of the EEPROM is connected to P0[5] pin of the board (also configured as SDA) and the SCL pin of EEPROM to P0[4] pin on the board. The bus lines (SDA and SCL) are pulled up via 3.3K resistors.

         

      I use the following code in the main.c file to read a byte in the EEPROM

         

      void ReadExtEEPROM(uint32 SlaveAddress,uint32 MemAddress){

         

          uint8 ret=0;

         

          I2C_I2CMasterClearStatus();

         

          I2C_I2CMasterSendStart(SlaveAddress,0);

         

          I2C_I2CMasterWriteByte(MemAddress>>8);

         

          I2C_I2CMasterWriteByte(MemAddress);    

         

          I2C_I2CMasterSendRestart(SlaveAddress,1);

         

          ret=I2C_I2CMasterReadByte(0);

         

          return (ret);

         

      }

         

       

         

      void WriteExtEEPROM(uint32 SlaveAddress,uint32 MemAddress,uint8 MemData){

         

          I2C_I2CMasterSendStart(SlaveAddress,0);

         

          I2C_I2CMasterWriteByte(MemAddress>>8);

         

          I2C_I2CMasterWriteByte(MemAddress);

         

          I2C_I2CMasterWriteByte(MemData);

         

          I2C_I2CMasterSendStop();

         

      }

         

       

         

      The problem is I can read the byte correctly for the first time (after power up) after which the reads always return 0. The address to which I read has be written previously (using the above WriteExtEEPROM) with a known value. So I know what value is expected..

         

      Please help...

         

      Thanks

         

      a