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

Problem on I2C

Hello Guys,

I was able to accomplish the I2C Interrupts ; When I created a separate project for I2C Interrupts I was able to read all the data on req addresses but later when I integrated the I2C Interrupt Routine with my current development application , I was able to read only the first ten address locations , the code remains the same. Where should be the problem ???

> Thanks for all your Support .

> Looking forward,
> Samjith

Parents Reply Children
  • The code is pasted below.I use LPC2368 as Master and CY8C20434(TouchKey Sensor IC) as my slave.The code works well if I create a separate project for I2C interrupt purpose . When I start integrating with my current project development I am able to read only some of the data locations in I2C .Why is that???

    
    __irq void I2C_IRQHandler(void)                                 /* I2C INTERRUPT HANDLER */
    {
    
            switch(I21STAT)
            {
    
                    case 0x08:                                                              /* ISSUE START CONDITION */
    
                            I21DAT = 0x22;                                      /* SLA + W (0x22 | 0x00) */
    
                        I21CONCLR = 0x20;                                   /* CLEAR START CONDITION */
    
                    break;
    
                    case 0x10:                                                              /* REPEATED START CONDITION */
    
                            I21DAT = 0x23;                                          /* SLA + R (0x22 | 0x01)   */
    
                            I21CONCLR = 0x20;                                   /* CLEAR START CONDITION   */
    
    
                    break;
    
                case 0x18:                                                       /* SLA + W (FOR WRITING STARTING ADDRESS OF SLAVE DATA */
    
                            I21DAT = 0x00;                                           /* CAPSENSE STARTING ADDRESS */
    
                            I21CONSET = 0x04;                                        /* SET ACKNOWLEDGEMENT BIT  */
    
                    break;
    
    
                    case 0x28:                                                                /* CAPSENSE STARTING ADDRESS TRANSMITTED , ACK RECEIVED */
    
                            I21CONSET = 0x20;                                         /* ISSUSE START CONDITION */
    
                            I21CONCLR = 0x04;
    
            break;
    
    
                    case 0x38:
    
                            I21CONSET = 0x20;                                           /* START CONDITION ISSUED IF ARBITRATION LOST WITH ACK */
    
    
            break;
    
                case 0x40:                                                                  /* SLA + R TRANSMITTED ACK RECEIVED */
    
                            I21CONSET = 0x04;                                               /* SET ACKNOWLEDGEMENT BIT */
    
                    break;
    
                    case 0x48:                                                                      /* SLA + R TRANSMITTED NACK RECEIVED */
    
                            I21CONSET = 0x20;                                           /* SET STOP BIT */
    
                    break;
    
                    case 0x50:                                                                      /* DATA BYTE RECEIVED WITH ACK */
    
    
                             MasterBuff[Read_Index] = I21DAT;
    
                             if(Read_Index != Read_Length)
                             {
    
                                    I21CONSET = 0x04;
                                    Read_Index++;
                                    Capsense_Driver();
    
                             }
    
                             else
                             {
    
                                    Read_Index = 0;
                                    I21CONCLR = 0x04;
    
                             }
    
    
    
                    break;
    
                    case 0x58:
    
    
                               I21CONSET = 0x20;
    
    
                    break;
    
    
    
                    default :
    
                    break;
    
               }
    
    
    
                    I21CONCLR = 0x08;                                               /* Clear I2C Interrupt Flag             */
                    VICVectAddr = 0;                                                        /* Acknowledge Interrupt */
    
    
    
    }
    
    

    Looking forward,
    Samjith

  • Hi Samjith Wasim,

    case 0x58:
        I21CONSET = 0x20;
        break;
    

    case 0x58 is
    Master Receiver mode;
    Data byte has been received; NOT ACK has been returned.

    Why set start flag?

    You need to:

    1. Re-read the manual, re-write your code.

    2. Trace your code step by step.

  • Hello John,

    Because case 0x58 is a state where NACK is recevied , So in the manual they have specified under case 0x58 which means NACK received , please re-start the communication .
    Thats why I provided with I2CONSET =0x20 (Start Condition).

    Thanks for your Support,
    Looking forward,
    Samjith.

  • -> When I created a separate project for I2C Interrupts I was able to read all the data on req addresses <-

    I would suggest that, check the working fine separate project,

    1. call the I2C reading procedure within a loop, lets say, loop for 20 times,

    2. and make sure that, you can get all the data correctly each time.