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/MSP430FR2355: LED blinking code with timer interruppt

Part Number: MSP430FR2355

Tool/software: Code Composer Studio

I am finding difficulty with LED blinking code with LED toggling in Timer interval. 

Please let me know the issues and the changes required


//Header Files//
#include "msp430fr2355.h"
#include "stdint.h"

#define CALTDH0CTL1_256 *((unsigned int *)0x1A36)

void Init_Clocks (void);
void init_IO (void);
void init_WDT (void);
void init_TimerB (void);

void main (void)
{

WDTCTL = WDTPW + WDTHOLD; // Stop WDT
_delay_cycles(1000000);
Init_Clocks (); // Initialize clocks for 25 MHz


init_TimerB ();

init_WDT ();
init_IO ();

PM5CTL0 &= ~LOCKLPM5; // Engage GPIOs
__enable_interrupt(); // Set GIE


_delay_cycles(1000000);

while(1)
{
; //
}
}
//end main

//WDT to restart ADC
void init_WDT (void)
{

WDTCTL = WDT_MDLY_32; // WDT 32ms from 1MHz, SMCLK, interval timer
SFRIE1 |= WDTIE; // Enable WDT interrupt
}


void init_TimerB (void)
{

TB3CTL = TBSSEL__SMCLK | MC_3 | TBCLR; // SMCLK, up_down mode, clear TBR
TB3CCR0 = 3276;
TB3CCR1 = 1676;
TB3CCTL0 |= CCIE;

__bis_SR_register(GIE); // enable interrupts
__no_operation(); // For debugger

_EINT(); // Enable interrupts

}


// Clocks And Vcore
void Init_Clocks (void)
{

FRCTL0 = FRCTLPW | NWAITS_2;

__bis_SR_register(SCG0); // disable FLL
CSCTL3 |= SELREF__REFOCLK; // Set REFO as FLL reference source
CSCTL0 = 0; // clear DCO and MOD registers
CSCTL1 |= DCORSEL_7; // Set DCO = 24MHz
CSCTL2 = FLLD_0 + 731; // DCOCLKDIV = 24MHz
__delay_cycles(3);
__bic_SR_register(SCG0); // enable FLL
while(CSCTL7 & (FLLUNLOCK0 | FLLUNLOCK1)); // FLL locked

CSCTL4 = SELMS__DCOCLKDIV | SELA__REFOCLK; // set default REFO(~32768Hz) as ACLK source, ACLK = 32768Hz
// default DCOCLKDIV as MCLK and SMCLK source
}

//IO INITIALISATION//
void init_IO (void)
{

//Indications
P2SEL0 &= ~ (BIT6); //GPIO-LED3
P2DIR |= (BIT6); //Output-LED3

__bis_SR_register(GIE);

}

/**************************************TIMERD0.1 INTERRUPT********************************************/

// Timer B1 interrupt service routine
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector = TIMER3_B0_VECTOR
__interrupt void Timer3_B0_ISR(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(TIMER3_B0_VECTOR))) Timer3_B0_ISR (void)
#else
#error Compiler not supported!
#endif
{

P2OUT |= ~(BIT6);
TB3CCTL1 &= ~CCIFG;

}

  • Hi Jeet,

    Please enable the Timer B Interrupt Enable bit to trigger the interrupt:

    TB3CTL = TBSSEL__SMCLK | MC_3 | TBCLR | TBIE; // SMCLK, up_down mode, clear TBR

  • >SFRIE1 |= WDTIE; // Enable WDT interrupt

    I don't see an ISR for this interrupt (WDT_VECTOR). Your program will freeze when it goes off.

  • I added the changes as suggested but still my codes goes inside timer interrupt once and then halts there and doesn't come out.

    Do have a look on code.


    //Header Files//
    #include "msp430fr2355.h"
    #include "stdint.h"

    #define CALTDH0CTL1_256 *((unsigned int *)0x1A36)

    void Init_Clocks (void);
    void init_IO (void);
    void init_WDT (void);
    void init_TimerB (void);

    unsigned int i = 0;
    unsigned int j = 0;

    void main (void)
    {

    WDTCTL = WDTPW + WDTHOLD; // Stop WDT
    _delay_cycles(1000000);
    Init_Clocks (); // Initialize clocks for 25 MHz


    // init_TimerB ();

    // init_WDT ();
    init_IO ();

    PM5CTL0 &= ~LOCKLPM5; // Engage GPIOs
    // __enable_interrupt(); // Set GIE


    _delay_cycles(1000000);

    while(1)
    {
    j++;
    if (j > 10000)
    {
    j = 0;
    }
    }
    }
    //end main

    //WDT to restart ADC
    void init_WDT (void)
    {

    WDTCTL = WDT_MDLY_32; // WDT 32ms from 1MHz, SMCLK, interval timer
    //SFRIE1 |= WDTIE; // Enable WDT interrupt
    }


    void init_TimerB (void)
    {

    TB3CTL = TBSSEL__ACLK | MC_3 | TBCLR | TBIE; // SMCLK, up_down mode, clear TBR
    TB3CCR0 = 3276;
    TB3CCR1 = 1676;
    TB3CCTL0 |= CCIE;

    __bis_SR_register(GIE); // enable interrupts
    __no_operation(); // For debugger

    _EINT(); // Enable interrupts

    }


    // Clocks And Vcore
    void Init_Clocks (void)
    {

    FRCTL0 = FRCTLPW | NWAITS_2;

    __bis_SR_register(SCG0); // disable FLL
    CSCTL3 |= SELREF__REFOCLK; // Set REFO as FLL reference source
    CSCTL0 = 0; // clear DCO and MOD registers
    CSCTL1 |= DCORSEL_7; // Set DCO = 24MHz
    CSCTL2 = FLLD_0 + 731; // DCOCLKDIV = 24MHz
    __delay_cycles(3);
    __bic_SR_register(SCG0); // enable FLL
    while(CSCTL7 & (FLLUNLOCK0 | FLLUNLOCK1)); // FLL locked

    CSCTL4 = SELMS__DCOCLKDIV | SELA__REFOCLK; // set default REFO(~32768Hz) as ACLK source, ACLK = 32768Hz
    // default DCOCLKDIV as MCLK and SMCLK source
    }

    //IO INITIALISATION//
    void init_IO (void)
    {

    //Indications
    P2SEL0 &= ~ (BIT6); //GPIO-LED3
    P2DIR |= (BIT6); //Output-LED3

    __bis_SR_register(GIE);

    }

    /**************************************TIMERD0.1 INTERRUPT********************************************/

    // Timer B1 interrupt service routine
    #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
    #pragma vector = TIMER3_B0_VECTOR
    __interrupt void Timer3_B0_ISR(void)
    #elif defined(__GNUC__)
    void __attribute__ ((interrupt(TIMER3_B0_VECTOR))) Timer3_B0_ISR (void)
    #else
    #error Compiler not supported!
    #endif
    {

    if (i > 100)
    {
    i = 0;
    P2OUT |= (BIT6);
    }
    else
    {
    i++;
    }

    TB3CCTL1 &= ~CCIFG;
    TB3CTL &= ~TBIFG;

    }

  • I added the changes as suggested but still my codes goes inside timer interrupt once and then halts there and doesn't come out.

    Do have a look on code.


    //Header Files//
    #include "msp430fr2355.h"
    #include "stdint.h"

    #define CALTDH0CTL1_256 *((unsigned int *)0x1A36)

    void Init_Clocks (void);
    void init_IO (void);
    void init_WDT (void);
    void init_TimerB (void);

    unsigned int i = 0;
    unsigned int j = 0;

    void main (void)
    {

    WDTCTL = WDTPW + WDTHOLD; // Stop WDT
    _delay_cycles(1000000);
    Init_Clocks (); // Initialize clocks for 25 MHz


    // init_TimerB ();

    // init_WDT ();
    init_IO ();

    PM5CTL0 &= ~LOCKLPM5; // Engage GPIOs
    // __enable_interrupt(); // Set GIE


    _delay_cycles(1000000);

    while(1)
    {
    j++;
    if (j > 10000)
    {
    j = 0;
    }
    }
    }
    //end main

    //WDT to restart ADC
    void init_WDT (void)
    {

    WDTCTL = WDT_MDLY_32; // WDT 32ms from 1MHz, SMCLK, interval timer
    //SFRIE1 |= WDTIE; // Enable WDT interrupt
    }


    void init_TimerB (void)
    {

    TB3CTL = TBSSEL__ACLK | MC_3 | TBCLR | TBIE; // SMCLK, up_down mode, clear TBR
    TB3CCR0 = 3276;
    TB3CCR1 = 1676;
    TB3CCTL0 |= CCIE;

    __bis_SR_register(GIE); // enable interrupts
    __no_operation(); // For debugger

    _EINT(); // Enable interrupts

    }


    // Clocks And Vcore
    void Init_Clocks (void)
    {

    FRCTL0 = FRCTLPW | NWAITS_2;

    __bis_SR_register(SCG0); // disable FLL
    CSCTL3 |= SELREF__REFOCLK; // Set REFO as FLL reference source
    CSCTL0 = 0; // clear DCO and MOD registers
    CSCTL1 |= DCORSEL_7; // Set DCO = 24MHz
    CSCTL2 = FLLD_0 + 731; // DCOCLKDIV = 24MHz
    __delay_cycles(3);
    __bic_SR_register(SCG0); // enable FLL
    while(CSCTL7 & (FLLUNLOCK0 | FLLUNLOCK1)); // FLL locked

    CSCTL4 = SELMS__DCOCLKDIV | SELA__REFOCLK; // set default REFO(~32768Hz) as ACLK source, ACLK = 32768Hz
    // default DCOCLKDIV as MCLK and SMCLK source
    }

    //IO INITIALISATION//
    void init_IO (void)
    {

    //Indications
    P2SEL0 &= ~ (BIT6); //GPIO-LED3
    P2DIR |= (BIT6); //Output-LED3

    __bis_SR_register(GIE);

    }

    /**************************************TIMERD0.1 INTERRUPT********************************************/

    // Timer B1 interrupt service routine
    #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
    #pragma vector = TIMER3_B0_VECTOR
    __interrupt void Timer3_B0_ISR(void)
    #elif defined(__GNUC__)
    void __attribute__ ((interrupt(TIMER3_B0_VECTOR))) Timer3_B0_ISR (void)
    #else
    #error Compiler not supported!
    #endif
    {

    if (i > 100)
    {
    i = 0;
    P2OUT |= (BIT6);
    }
    else
    {
    i++;
    }

    TB3CCTL1 &= ~CCIFG;
    TB3CTL &= ~TBIFG;

    }

  • > TB3CTL = TBSSEL__ACLK | MC_3 | TBCLR | TBIE; // SMCLK, up_down mode, clear TBR

    Remove TBIE from this line, since you don't have a TIMER3_B1_VECTOR (and I suspect you don't want one).

**Attention** This is a public forum