This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

i2c problem

respected sir

i m using lpc2378 and i m trying to implement i2c protocol with at24c512 eeprom
when i m transmitting data then i m gettting ack but when i rx then i m not gettting ack
pls tell m where is i m wrong

o/p of that program is ABCDA1A1FA185G

        /******* i2c init *******/
        PINSEL0          = 0x50;                                                //Switch GPIO to I2C pins
        PCONP |= (1 << 19);
        PINSEL1 &= ~0x03C00000;
        PINSEL1 |= 0x01400000;  /* set PIO0.27 and PIO0.28 to I2C0 SDA and SCK */
        /* Initialize I2C */
        I20CONCLR=0x6c; /* clearing all flags */
        I20CONSET=0x40; /* enabling I2C */
        I20SCLH=60; /* BIT FREQ 100 KHz  & PCLK 12MZ*/
        I20SCLL=60;

while(1){

        I20CONSET=0x60;
        Delay(100);
        if(I20STAT ==0x08)
        {
                IOCLR0=0x10;
        /* Slave address + write */
                I20DAT=0xA0;
        /* Clear SI and Start flag */
                I20CONCLR=0x28;
        /* Port Indicator */
                IOSET0=0x10;
                TransmitChar0('A');
                Delay(100);
         }

        if(I20STAT ==0x18)
        {
        /* Port Indicator */
                IOCLR0=0x20;
        /* Data to be transmitted */
                I20DAT=0xFF;  //ADDRESS
        /* clear SI */
                I20CONCLR=0x8;
        /* Port Indicator */
                IOSET0=0x20;
                TransmitChar0('B');
                Delay(100);
//      }
//      if(I20STAT ==0x18)
//      {
        /* Port Indicator */
                IOCLR0=0x20;
        /* Data to be transmitted */
                I20DAT='O';     //DATA
        /* clear SI */
                I20CONCLR=0x8;
        /* Port Indicator */
                IOSET0=0x20;
                TransmitChar0('C');
                Delay(100);
        }
        if(I20STAT ==0x28)
        {
                IOCLR0=0x80;
        /* Transmit stop condition */
                I20CONSET=0x10;
        /* clear SI */
                I20CONCLR=0x8;
        /* Port Indicator */
                IOSET0=0x80;
                TransmitChar0('D');
    /*--- Wait for STOP detected ---*/
          while( I20CONSET & 0x10 );
                Delay(100);
                I20CONSET=0x20;
                I20CONSET=0x40;
                Delay(100);

        }

   /************** RECEIVER     ******************/
        if(I20STAT ==0x10)
        {
                I20CONCLR =  0x20 ;              //     if(I20STAT &=0x08)                                                          //Start bit
            I20CONCLR =  0x08 ;
                Delay(100);
                I20DAT          = 0xA1;         //Send address and write bit
                I20CONCLR =  0x08 ;
                TransmitChar0('E');
                Delay(100);
        }
        if(I20STAT ==0x08)
        {
                IOCLR0=0x10;
        // Slave address + write
                I20DAT=0xA1;
                TransmitChar0(I20DAT);

        // Clear SI and Start flag
                I20CONCLR=0x28;
        // Port Indicator
                IOSET0=0x10;
                TransmitChar0(I20DAT);

                TransmitChar0('F');
                Delay(100);
         }
        if(I20STAT ==0x40)              //Slave address+r, ACK
        {
//              I20DAT   = 0x0f;                //Write Mem,ory start address to tx register
//              TransmitChar0(I20DAT);
                TransmitChar0(I20DAT);
                I20CONCLR =  0x08 ;
                Delay(100);
                TransmitChar0(I20DAT);
                TransmitChar0('G');
                Delay(100);
        }
        if(I20STAT ==0x48)              //Slave address+r, ACK
        {
                I20CONCLR =  0x20 ;              //     if(I20STAT &=0x08)                                                          //Start bit
            I20CONCLR =  0x08 ;
                Delay(100);
                I20DAT          = 0xA1;         //Send address and write bit
                I20CONCLR =  0x08 ;
                TransmitChar0('H');
                Delay(100);
//              I20DAT   = 0x0f;                //Write Mem,ory start address to tx register
                TransmitChar0(I20DAT);
                I20CONCLR =  0x08 ;
                Delay(100);
                TransmitChar0('I');
                Delay(100);
        }

        if(I20STAT ==0x50)              //Slave address+r, ACK
        {
                TransmitChar0(I20DAT);
        /* Transmit stop condition */
                I20CONSET=0x10;
        /* clear SI */
                I20CONCLR=0x8;
                TransmitChar0('J');
        }
  }

thank u