This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

I2C Issue in receiving repeated single byte data from slave ,master does not acknowledge

I am working with MSP430F55xx as slave and  MSP43056xx as a master. I want to receive 1 kB data from the slave repeatedly. In the master, I have a timer which interrupts the CPU every 500 ms to write 1 byte command to the slave, otherwise master always requests 1 kB data from the slave. I am able to recieve 1 kB data for the first time , but then as observed in the oscilloscope, the master does not acknowledge to the slave anymore. As soon as the timer is on,  I2C communication stops. Any suggestion on what is wrong with the protocol? Snipet of the master code is given below.

int main(void)

{

timer_init();

 I2C_init ();

                      while(1)

   {

         __bis_SR_register( GIE);                           // Enter LPM0, enable interrupts

                              

if ((timer_flag==1) 

{

                                 timer_flag=0;

                                  while (UCB1CTL1 & UCTXSTP);                                   // Ensure no stop condition

       UCB1I2CSA = 0x00;                                                   // Broadcast

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

                             UCB1TXBUF = 0x55;                                      // Load TX buffer

                                for (i=0;i<10;i++);

                             UCB1CTL1 |= UCTXSTP;                                      // I2C stop condition

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

                                for (i=0;i<10;i++);

    }

 

receive_bytes

{                                                                                     __bic_SR_register( GIE);                           // Disbale All int.

                                                                                 RXByteCtr=1024;

                                                                               UCB1I2CSA = 0x47;                                        // Slave's address

                                                                                      UCB1IE |= UCRXIE+ UCNACKIE;

                                                                                      UCB1CTL1 &= ~ UCTR ;

                                                                                       while (UCB1CTL1 & UCTXSTP);

                                                                                       UCB1IE |= UCRXIE+ UCNACKIE;

                                                                                      __bis_SR_register( GIE);

                                                                                    UCB1CTL1 |= UCTXSTT;

                                                                                      for (i=0;i<10;i++);

                             }

                }

//------------------------------------------------------------------------------

#pragma vector = USCI_B1_VECTOR

__interrupt void USCI_B1_ISR(void)

 

{

  switch(__even_in_range(UCB1IV,12))

  {

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

  case  2: break;                           // Vector  2: ALIFG

  case  4:

UCB1CTL1 |= UCTXSTP;

                break;                           // Vector  4: NACKIFG

  case  6: break;                          // Vector  6: STTIFG

  case  8: break;                           // Vector  8: STPIFG

 

  case 10:                                  // CCN Recieves DATA

                                          RXData = UCB1RXBUF;

          break;

 }

}

 

#pragma vector=TIMERB0_VECTOR

__interrupt void TIMERB0_ISR (void)

{

       timer_flag=1;

 

}

  • To insert code, please use the </> button.

    A waiting loop like "for (i=0;i<10;i++);" is never correct. If you want to wait for some specific event, just do it.
    To send a single byte, wait for TXIFG to be set before setting TXSTP.

    I don't quite understand the receive code. Why are you setting TXSTT at the end?

  • In the while , you write a byte whenever your timer flag is 1 otherwise you request the slave to send 1kB data. TXSTT starts the I2C communication with master in the receiving mode. The I2C_init in the beginning initialize the I2C registers and put the master in the transmitting mode.

  • // Enter LPM0

    This comment is wrong.

    Is that "receive_bytes" supposed to be an "else"? If yes, the loop repeatedly initializes the receiving mode.

**Attention** This is a public forum