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.

CCS/MSP430FR5738: Not entering into interrupt

Part Number: MSP430FR5738
Other Parts Discussed in Thread: MSP-EXP430FR5739

Tool/software: Code Composer Studio

I am using msp430fr5738 microcontroller, I was flashed with example code, but it was not working. It was stops in this line. I was enable interrupt also. How to solve this problem

#include "driverlib.h"
#include <stdio.h>

//******************************************************************************
#define SLAVE_ADDRESS 0x3b
unsigned char TXData =0; // Pointer to TX data
unsigned char TXByteCtr;

void main (void)
{
//Stop WDT
WDT_A_hold(WDT_A_BASE);
// Configure Pins for I2C
P1SEL1 |= BIT6 + BIT7; // Pin init

UCB0CTLW0 |= UCSWRST; // put eUSCI_B in reset state
UCB0CTLW0 |= UCMODE_3 + UCMST + UCSSEL_2 | UCTR;// I2C master mode, SMCLk
UCB0BRW = 0x8; // baudrate = SMCLK / 8
UCB0I2CSA = 0x3A; // address slave is 48hex
UCB0CTLW0 &=~ UCSWRST; //clear reset register
UCB0IE |= UCTXIE0 + UCNACKIE;  //transmit  interrupt enable

while(1)
{
// __delay_cycles(1000); // Delay between transmissions
TXByteCtr = 1; // Load TX byte counter
while (UCB0CTLW0 & UCTXSTP); // Ensure stop condition got sent
UCB0CTLW0 |= UCTR + UCTXSTT; // I2C TX, start condition

__bis_SR_register(CPUOFF + GIE); // Enter LPM0 w/ interrupts
// Remain in LPM0 until all data
// is TX'd
TXData++; // Increment data byte
}

}

#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector = USCI_B0_VECTOR
__interrupt void USCIB0_ISR(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(USCI_B0_VECTOR))) USCIB0_ISR (void)
#else
#error Compiler not supported!
#endif
{
switch(__even_in_range(UCB0IV,0x1E))
{
case 0x00: break; // Vector 0: No interrupts break;
case 0x02: break;
case 0x04:
UCB0CTLW0 |= UCTXSTT; //resend start if NACK
break; // Vector 4: NACKIFG break;
case 0x18:
if (TXByteCtr) // Check TX byte counter
{
UCB0TXBUF = TXData; // Load TX buffer
TXByteCtr--; // Decrement TX byte counter
}
else
{
UCB0CTLW0 |= UCTXSTP; // I2C stop condition
UCB0IFG &= ~UCTXIFG; // Clear USCI_B0 TX int flag
__bic_SR_register_on_exit(CPUOFF);// Exit LPM0
}
break; // Vector 26: TXIFG0 break;
default: break;
}
}

  • Part Number: MSP430FR5738

    Tool/software: Code Composer Studio

    I am using msp430fr5738 microcontroller, I was flashed with example code, but it was not working. It was stops in this line (In above code stops  in this line not entering into interrupt __bis_SR_register(CPUOFF + GIE); . I was enable interrupt also. How to solve this problem

    #include "driverlib.h"
    #include <stdio.h>

    //******************************************************************************
    #define SLAVE_ADDRESS 0x3b
    unsigned char TXData =0; // Pointer to TX data
    unsigned char TXByteCtr;

    void main (void)
    {
    //Stop WDT
    WDT_A_hold(WDT_A_BASE);
    // Configure Pins for I2C
    P1SEL1 |= BIT6 + BIT7; // Pin init

    UCB0CTLW0 |= UCSWRST; // put eUSCI_B in reset state
    UCB0CTLW0 |= UCMODE_3 + UCMST + UCSSEL_2 | UCTR;// I2C master mode, SMCLk
    UCB0BRW = 0x8; // baudrate = SMCLK / 8
    UCB0I2CSA = 0x3A; // address slave is 48hex
    UCB0CTLW0 &=~ UCSWRST; //clear reset register
    UCB0IE |= UCTXIE0 + UCNACKIE;  //transmit  interrupt enable

    while(1)
    {
    // __delay_cycles(1000); // Delay between transmissions
    TXByteCtr = 1; // Load TX byte counter
    while (UCB0CTLW0 & UCTXSTP); // Ensure stop condition got sent
    UCB0CTLW0 |= UCTR + UCTXSTT; // I2C TX, start condition

    __bis_SR_register(CPUOFF + GIE); // Enter LPM0 w/ interrupts
    // Remain in LPM0 until all data
    // is TX'd
    TXData++; // Increment data byte
    }

    }

    #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
    #pragma vector = USCI_B0_VECTOR
    __interrupt void USCIB0_ISR(void)
    #elif defined(__GNUC__)
    void __attribute__ ((interrupt(USCI_B0_VECTOR))) USCIB0_ISR (void)
    #else
    #error Compiler not supported!
    #endif
    {
    switch(__even_in_range(UCB0IV,0x1E))
    {
    case 0x00: break; // Vector 0: No interrupts break;
    case 0x02: break;
    case 0x04:
    UCB0CTLW0 |= UCTXSTT; //resend start if NACK
    break; // Vector 4: NACKIFG break;
    case 0x18:
    if (TXByteCtr) // Check TX byte counter
    {
    UCB0TXBUF = TXData; // Load TX buffer
    TXByteCtr--; // Decrement TX byte counter
    }
    else
    {
    UCB0CTLW0 |= UCTXSTP; // I2C stop condition
    UCB0IFG &= ~UCTXIFG; // Clear USCI_B0 TX int flag
    __bic_SR_register_on_exit(CPUOFF);// Exit LPM0
    }
    break; // Vector 26: TXIFG0 break;
    default: break;
    }
    }

  • Hello,

    Could you please provide more detail of the specific example code you are referencing so I can try to recreate the issue? Also, have you made any modifications to the example?

    Best regards,

    Matt
  • FYI I merged your newest thread referencing the same issue because it is best practice to keep support on an issue local to its initial thread. Thank you for your understanding.

    Best regards,

    Matt
  • How do you know you're not going to the ISR? Did you set a breakpoint at the first line?
  • I put break point in inside of the TX interrupt and also step by step execution in debug mode
  • I was changed slave address only
  • Most probable: Your bus pullups aren't installed properly.

    I added these two lines (msp-exp430fr5739) and it got to the ISR. (It got NACKed, of course, because I didn't have a slave attached.) This is not a fix -- you really should have external pullups.

        P1OUT |= BIT6|BIT7;     // Internal pullups
        P1REN |= BIT6|BIT7;     //   (for demonstration only)
    

  • Still not working, UCTXIFG0 this flag is not set, when i sent start
  • When I did what I described, I saw the TXIFG set, but the NACKIFG took precedence. Then the re-start cleared the TXIFG.

    I don't know the answer, and I don't have your equipment. It works as expected on my equipment.

    What pullups do you have installed? What is your slave device?
  • my slave is MMA8652(accelerometer). When i send start, high to low transition is not occur. In UCB0STATW register bus busy bit is high.
  • This is my code


    #include "driverlib.h"
    #include <stdio.h>

    //******************************************************************************
    #define SLAVE_ADDRESS 0x3A
    unsigned char TXData =0; // Pointer to TX data
    unsigned char TXByteCtr;

    void main (void)
    {
    //Stop WDT
    WDT_A_hold(WDT_A_BASE);
    // Configure Pins for I2C
    // P1OUT |= BIT6 | BIT7;
    P1REN |= BIT6 | BIT7;
    P1SEL1 |= BIT6 + BIT7; // Pin init

    UCB0CTLW0 |= UCSWRST; // put eUSCI_B in reset state
    UCB0CTLW0 |= UCMODE_3 + UCMST + UCSSEL_2 + UCSYNC;// I2C master mode, SMCLk
    UCB0BRW = 0x8; // baudrate = SMCLK / 8
    UCB0I2CSA = SLAVE_ADDRESS; // address slave is 3Ahex
    UCB0CTLW0 &=~ UCSWRST; //clear reset register
    UCB0IE |= UCTXIE0 + UCNACKIE; //transmit and NACK interrupt enable

    while(1)
    {
    // __delay_cycles(1000); // Delay between transmissions
    TXByteCtr = 1; // Load TX byte counter
    while (UCB0CTLW0 & UCTXSTP); // Ensure stop condition got sent
    UCB0CTLW0 |= UCTR + UCTXSTT; // I2C TX, start condition

    __bis_SR_register(CPUOFF | GIE); // Enter LPM0 w/ interrupts
    __no_operation(); // Remain in LPM0 until all data
    // is TX'd
    TXData++; // Increment data byte
    }



    }



    #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
    #pragma vector = USCI_B0_VECTOR
    __interrupt void USCIB0_ISR(void)
    #elif defined(__GNUC__)
    void __attribute__ ((interrupt(USCI_B0_VECTOR))) USCIB0_ISR (void)
    #else
    #error Compiler not supported!
    #endif
    {
    switch(__even_in_range(UCB0IV,0x1E))
    {
    case 0x00: break; // Vector 0: No interrupts break;
    case 0x02: break;
    case 0x04:
    UCB0CTLW0 |= UCTXSTT; //resend start if NACK
    break; // Vector 4: NACKIFG break;
    case 0x18:
    if (TXByteCtr) // Check TX byte counter
    {
    UCB0TXBUF = TXData; // Load TX buffer
    TXByteCtr--; // Decrement TX byte counter
    }
    else
    {
    UCB0CTLW0 |= UCTXSTP; // I2C stop condition
    UCB0IFG &= ~UCTXIFG; // Clear USCI_B0 TX int flag
    __bic_SR_register_on_exit(CPUOFF);// Exit LPM0
    }
    break; // Vector 26: TXIFG0 break;
    default: break;
    }
    }
  • > #define SLAVE_ADDRESS 0x3A
    According to MMA8652FC data sheet (Rev 3.3) Table 1, the I2C address is 0x1D. (The R/W bit is not part of the address.)

    [Edit: I just noticed this:]

    >// P1OUT |= BIT6 | BIT7;
    >P1REN |= BIT6 | BIT7;

    This enables the resistors in some unknown state. Either use both of these lines or neither (I recommend "neither").

  •  Now also the same , not working

    #include "driverlib.h"

    #include <stdio.h>

    //******************************************************************************

    #define SLAVE_ADDRESS 0x1D

    unsigned char TXData =0;                    // Pointer to TX data

    unsigned char TXByteCtr;

    void main (void)

    {

       //Stop WDT

       WDT_A_hold(WDT_A_BASE);

       // Configure Pins for I2C

       P1OUT |= BIT6 | BIT7;

       P1REN |= BIT6 | BIT7;

       P1SEL1 |= BIT6 + BIT7;                  // Pin init

       UCB0CTLW0 |= UCSWRST;                   // put eUSCI_B in reset state

       UCB0CTLW0 |= UCMODE_3 + UCMST + UCSSEL_2  + UCSYNC;// I2C master mode, SMCLk

       UCB0BRW = 0x8;                          // baudrate = SMCLK / 8

       UCB0I2CSA = SLAVE_ADDRESS;                       // address slave is 3Ahex

       UCB0CTLW0 &=~ UCSWRST;              //clear reset register

       UCB0IE |= UCTXIE0 + UCNACKIE;           //transmit and NACK interrupt enable

       while(1)

       {

      // __delay_cycles(1000);                   // Delay between transmissions

       TXByteCtr = 1;                          // Load TX byte counter

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

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

       __bis_SR_register(CPUOFF | GIE);        // Enter LPM0 w/ interrupts

        //  __no_operation();                                     // Remain in LPM0 until all data

                                               // is TX'd

       TXData++;                               // Increment data byte

       }

    }

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

    #pragma vector = USCI_B0_VECTOR

    __interrupt void USCIB0_ISR(void)

    #elif defined(__GNUC__)

    void __attribute__ ((interrupt(USCI_B0_VECTOR))) USCIB0_ISR (void)

    #else

    #error Compiler not supported!

    #endif

    {

     switch(__even_in_range(UCB0IV,0x1E))

     {

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

           case 0x02: break;

           case 0x04:

             UCB0CTLW0 |= UCTXSTT;             //resend start if NACK

             break;                            // Vector 4: NACKIFG break;

           case 0x18:

         if (TXByteCtr)                    // Check TX byte counter

             {

               UCB0TXBUF = TXData;             // Load TX buffer

               TXByteCtr--;                    // Decrement TX byte counter

             }

             else

             {

               UCB0CTLW0 |= UCTXSTP;           // I2C stop condition

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

               __bic_SR_register_on_exit(CPUOFF);// Exit LPM0

             }

             break;                            // Vector 26: TXIFG0 break;

           default: break;

     }

    }

  • I was changed slave address
  • What kind of pullup resistors do you have installed?
  • Hello,

    We haven’t heard from you for a few days so I’m assuming you were able to resolve your issue. If this isn’t the case, please click the "This did NOT resolve my issue" button and reply to this thread with more information regarding Bruce's question and any other new information you have. If this thread locks, please click the "Ask a related question" button and in the new thread describe the current status of your issue and any additional details you may have to assist us in helping to solve your issues.

    Regards,
    Matt

**Attention** This is a public forum