Quantcast
Channel: MSP430 Technical Forums
Viewing all articles
Browse latest Browse all 2077

Issue with I2C Receive Interrupt

$
0
0
I have problem with the following code. I am trying to communicate with Master and Slave. I want master to issue some command to the slave(To start ADC on the slave) and then start reading the data from slave. The problem is that my code does not enter the RX interrupt routine of the ISR i.e case 10. Any help is appreciated.
 

int main(void)

{

  

   // I2C with USCI_B1 registers

  P8SEL |= 0x60;                                // Assign I2C pins to USCI_B0 P8.5 and P8.6

  UCB1CTL1 |= UCSWRST;                          // Enable SW reset

  UCB1CTL0 = UCMST + UCMODE_3 + UCSYNC;         // I2C Master, synchronous mode

  UCB1CTL1 = UCSSEL_2 + UCSWRST;                // Use SMCLK

  UCB1BR0 = 12;                                 // fSCL = SMCLK/12 = ~100kHz

  UCB1BR1 = 0;

  UCB1CTL1 &= ~UCSWRST;                         // Clear SW reset, USCI resume operation

  UCB1IE |= UCRXIE+UCTXIE + UCSTTIE + UCSTPIE;         // Enable RX interrupt,TX interrupt

  UCB1I2CSA = 0x48;                             // Broadcast message

  TXByteCtr = 1;                                //  TX byte counter =1 for command

 __enable_interrupt();

  while (1)

  {

  // Transmit 1byte data to SLave

 if(TXByteCtr == 1)

 {

 while (UCB1CTL1 & UCTXSTP);                   // Ensure stop condition got sent

   UCB1CTL1 |= UCTR + UCTXSTT;                   // I2C TX, start condition

}

 else

 {

 UCB1I2CSA = 0x48;                           // Slave adrres  048h

  RXByteCtr = 3;                                   // receive 3 byte data from slave

    while (UCB1CTL1 & UCTXSTP);                 // Ensure stop condition got sent

    UCB1CTL1 |=  UCTXSTT;                       // I2C  start condition

    }

}

}

// USCI_B1 I2C Data ISR

#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)

#pragma vector = USCI_B1_VECTOR

__interrupt void USCI_B1_ISR(void)

#elif defined(__GNUC__)

void __attribute__ ((interrupt(USCI_B1_VECTOR))) USCI_B1_ISR (void)

#else

#error Compiler not supported!

#endif

{

  switch(__even_in_range(UCB1IV,12))

  {

  case  0: break;                               // Vector  0: No interrupts

  case  2: break;                               // Vector  2: ALIFG

  case  4: break;                               // Vector  4: NACKIFG

  case  6: break;                               // Vector  6: STTIFG

  case  8: break;                               // Vector  8: STPIFG

  case 10:                                      // Vector 10: RXIFG                                 <-------------<strong>The debugger never enters here.</strong>

    RXByteCtr--;                           // Decrement RX byte counter

    if (RXByteCtr)

                {

               done=UCB1RXBUF;

               reading = UCB1RXBUF;               // Move RX data

               reading <<= 8;

               if (RXByteCtr == 1)                // Only one byte left?

                  UCB1CTL1 |= UCTXSTP;               // Generate I2C stop condition

                 }

     else

                 {

               reading |= UCB1RXBUF;                 // Move final RX data

                              }

    if (done==0)

                  {

            data_1[index]=reading;

            index++;

                 }

    if (index == 64)

         {

          index = 0;                  // To check data

        }

   break;

  case 12:

    if (TXByteCtr==1)                                      // Check TX byte counter

                  {

                  UCB1TXBUF = 62;                        // Command to start the ADC on slave

                  TXByteCtr++;                           // Decrement TX byte counter

                  }

     else

                  {

                  UCB1CTL1 |= UCTXSTP;                   // I2C stop condition

                  UCB1IFG &= ~UCTXIFG;                   // Clear USCI_B0 TX int flag

                                  }

 break;                                                // Vector 12: TXIFG

      default: break;

  }


Viewing all articles
Browse latest Browse all 2077

Trending Articles