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

Modified from your feedback told Sir !

Dear Sir, with the feedback given by you I was able to re-structure my I2C Interrupt routine.Interrupt is invoking properly everytime, but I am not able to get the desired result.

I want to clarify that I am reading data from my master controller.


 My Slave has data like this.

   Location      Value
     0x00 --->    1
     0x01 --->    2
     0x02 --->    3

and so on till 0x23 ----> 24 .

In LPC2368 I have to use SLA+R protocol (Master-Receiver Mode)
Correct ???

If so below is my re-structured irq ...

__irq void I2C_IRQHandler(void)
{

   switch(I21STAT)    /* Checking each States */
   {

     case 0x08 :     /* Start Condition */

/* My Slave Address is 0x11 , but as we calculate to feed it in      I2C Protcol format we arrive as
                                                   (Read/Write)
   Bit Positions : 7    6    5    4    3    2    1     0
----------------------------------------------------------------
   Slave Address : 0    0    1    0    0    0    1     1 (Read)

Setting 0x11(Slave Address) along with the Read Bit ,I arrive at 0x23 for SLA+R (MASTER RECEVIVE)

        I21DAT = 0x23;  /* Feeding Slave Address SLA+R*/

        break;

     case 0x10 :   /* Repeated Start Condition */

         I21DAT = 0x23;  /* SLA+R */

         break;

     case 0x40 :  /* SLA+R Transmitted ACK Received */

        I21CONSET = 0x04; /*Send ACK from Master */

        break;

     case 0x48 : /* SLA+R Transmitted NO ACK */

       I21CONSET = 0x20;  /* Setting Start bit again */

       break;

     case 0x50 : /* Data Byte Received with ACK*/

       Message = I21DAT /* Reading Data and storing it in global variable unsigned char Message ; */

       I21CONSET = 0x04; /*Return back the ACK bit */

       break;

    case 0x58 : /* Data Byte Received with NO ACK returned*/

      I21CONSET = 0x20; /* Setting Start bit again */

      break;

   default :

     break ;

  }
   I21CONCLR = 0x08;    // Clear I2C Interrupt Flag
   VICVectAddr = 0;     // Acknowledge Interrupt

}


Other than my IRQ routine in my main I use this function


void main(void)
{

        PCONP |= 0x00080000;

        PINSEL1 |= 0x000003C0;  /* Setting Pin Selection for I2C1 */

        I21SCLL   = 60;         /* Speed at 100Khz  */
        I21SCLH   = 60;


        VICIntEnClr |= (1<<19);
        VICVectPriority19 = 1;
        VICVectAddr19 = (unsigned long)I2C_IRQHandler;
        VICIntEnable |= (1<<19);


 while(1)
  {

        I21CONSET = 0x00000040;  /* Setting I2Enable bit   */
        I21CONSET = 0x00000020;  /* Setting Start Bit */

       if(Message == 1)
       {
          LcdDisplay("Message is 1");
       }

      and so on....till Message == 23..
  }
}

I have tried placing I2Enable and Start bit outside the while(1) .But still I am not able to get the data from slave .

Please! Please help me on this issue if i was right with the protocol of I2C.


Regards,
Samjith

0