Quantcast
Channel: MSP low-power microcontroller forum - Recent Threads
Viewing all articles
Browse latest Browse all 21927

Problem in MSP430fr5949 I2C Master Mode Automatic STOP Generation

$
0
0

Hi,

I set MSP430fr5949 to master mode and activated the automatic stop generation function, then transmitted  a sequence of  command bytes to slave device.

The sequence should be Start -> Slave address -> Command code -> stop.

However, my program held on the command "__bis_SR_register(LPM0_bits | GIE);" after set start condition.

It may be related to the wrong configuration  that I used. Please help.

My code was posted below, CCS editor were used.

int main(void) {
    int initial_loop = 0;

    WDTCTL = WDTPW | WDTHOLD;    // Stop watchdog timer

    P1SEL1 |= BIT6 | BIT7;                            // I2C pins - P1.6 SDA, P1.7 SCL
    PM5CTL0 &= ~LOCKLPM5;                              // Disable the GPIO power-on default high-impedance mode to activate
    UCB0CTLW0 |= UCSWRST;                            // Software reset enabled
    UCB0CTLW0 |= UCMODE_3 | UCMST | UCSSEL__SMCLK;     // I2C master mode, SMCLK, Software reset enabled
    UCB0CTLW1 |= UCASTP_2;                            // Automatic stop generated

    UCB0I2CSA = LED_Driver_SlaveAddress;            // configure slave addressUCB0I2CSA = SlaveAddress;
    UCB0BRW = 0x2710;                               // fSCL = SMCLK/10000 = ~100Hz; HT16K33V110 maximun clock frequency = 400kHz
    UCB0TBCNT = 0x01;                                // number of bytes to be received

    UCB0CTLW0 &= ~UCSWRST;                            // clear reset register
    UCB0IE |= UCTXIE0 | UCNACKIE;                     // transmit and NACK interrupt enable

    //Tx_Initial`
    TXByteCtr = Num_Initial_Bytes;
    Copy_Array_Content(TxTempBuff, LED_Driver_Initialisation, TXByteCtr);
    for(;initial_loop < Num_Initial_Bytes; initial_loop++)
    {
        while(UCB0CTLW0 & UCTXSTP);                // Ensure stop condition sent
        UCB0CTLW0 |= UCTR | UCTXSTT;            // I2C TX, start condition
        __bis_SR_register(LPM0_bits | GIE);     // Enter LPM0 w/ interrupts Remain in LPM0 until all data is TX'd
    }

    UCB0CTLW1 |= UCASTP_0;                        // Turn off Automatic stop generated

    __no_operation();
}

#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector = USCI_B0_VECTOR
__interrupt void USCI_B0_ISR(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(USCI_B0_VECTOR))) USCI_B0_ISR (void)
#else
#error Compiler not supported!
#endif
{
  switch(__even_in_range(UCB0IV, USCI_I2C_UCBIT9IFG))
  {
    case USCI_NONE:          break;         // Vector 0: No interrupts
    case USCI_I2C_UCALIFG:   break;         // Vector 2: ALIFG
    case USCI_I2C_UCNACKIFG:                // Vector 4: NACKIFG
      UCB0CTLW0 |= UCTXSTT;                 // resend start if NACK
      break;
    case USCI_I2C_UCSTTIFG:  break;         // Vector 6: STTIFG
    case USCI_I2C_UCSTPIFG:  break;         // Vector 8: STPIFG
    case USCI_I2C_UCRXIFG3:  break;         // Vector 10: RXIFG3
    case USCI_I2C_UCTXIFG3:  break;         // Vector 12: TXIFG3
    case USCI_I2C_UCRXIFG2:  break;         // Vector 14: RXIFG2
    case USCI_I2C_UCTXIFG2:  break;         // Vector 16: TXIFG2
    case USCI_I2C_UCRXIFG1:  break;         // Vector 18: RXIFG1
    case USCI_I2C_UCTXIFG1:  break;         // Vector 20: TXIFG1
    case USCI_I2C_UCRXIFG0:  break;         // Vector 22: RXIFG0
    case USCI_I2C_UCTXIFG0:                 // Vector 24: TXIFG0
      {
          if (TXByteCtr)                        // Check TX byte counter
          {
              TXByteCtr--;                        // Decrement TX byte counter
              UCB0TXBUF = TxTempBuff[TXByteCtr];    // Load TX buffer
          }
          else
          {
              UCB0CTLW0 |= UCTXSTP;               // I2C stop condition
              UCB0IFG &= ~UCTXIFG;                // Clear USCI_B0 TX int flag
              __bic_SR_register_on_exit(LPM0_bits); // Exit LPM0
          }
      }
      break;
    default: break;
  }
}

Thank you.

Regards,

Sungming


Viewing all articles
Browse latest Browse all 21927

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>