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.

Clear GIE problem

Hi everyone, I wrote a program as below, and I want to disable gobal interrupt in timer ISR by ONLY GIE, but no effect, please help to solve my problem and please let me know where is my mistake.

Thank in advance!

#include <msp430.h> 
#include "MSP430_MACROs.h"
/*
 * main.c
 */
void TIM_TRIG_ADCs_CFG(){
	TA0CCTL0 &= ~CCIE;
	TACTL = TASSEL_2 + MC_1; // Set the timer A to SMCLCK, Continuous
	TA0CCR0 = 50000-1;
	TA0CCTL0 |= CCIE;
	_BIS_SR(GIE);
//	__enable_interrupt();
}
void delay_ms (int t)
{
	int i;
	for (i = 0; i<t; i++ )
		_delay_cycles(16000);
}
int count=0;
int main(void) {
    WDTCTL = WDTPW | WDTHOLD;	// Stop watchdog timer

    if (CALBC1_16MHZ==0xFF)					// If calibration constant erased
	{
		while(1);                			// do not load, trap CPU!!
	}
	// configure clock to 16 MHz
	BCSCTL1 = CALBC1_16MHZ;       			// DCO = 16 MHz
	DCOCTL = CALDCO_16MHZ;
	P1DIR |= LED_ALL;
	P1OUT &= ~LED_ALL;
	TIM_TRIG_ADCs_CFG();
	while(1){
	return 0;
}
}
int timerCount=0,tc1=0;
#pragma vector=TIMER0_A0_VECTOR
__interrupt void Timer_A00 (void)
{

	if((!((++timerCount)%96))){
		T(1,0);
		if(++tc1==8)
			__bic_SR_register(GIE);
	}
}

  • try _bic_SR_register_on_exit(GIE);

  • Hi Hcmut!

    hcmut said:
    want to disable gobal interrupt in timer ISR by ONLY GIE, but no effect

    What does that mean in deatil? Is the bit still set in the register overview when single stepping through the code? Add another expression after the __bic_sr instruction and single step over the instruction. Did you check if the rest of your program works properly?

    Dennis

  • yes, I tried, but the code in While not run, how I can fix that?

    #include <msp430.h> 
    #include "MSP430_MACROs.h"
    /*
     * main.c
     */
    void TIM_TRIG_ADCs_CFG(){
        TA0CCTL0 &= ~CCIE;
        TACTL = TASSEL_2 + MC_1; // Set the timer A to SMCLCK, Continuous
        TA0CCR0 = 50000-1;
        TA0CCTL0 |= CCIE;
        _BIS_SR(GIE);
    //  __enable_interrupt();
    }
    void delay_ms (int t)
    {
        int i;
        for (i = 0; i<t; i++ )
            _delay_cycles(16000);
    }
    int timerCount=0,tc1=0, ena =0;
    int count=0;
    int main(void) {
        WDTCTL = WDTPW | WDTHOLD;   // Stop watchdog timer
    
        if (CALBC1_16MHZ==0xFF)                 // If calibration constant erased
        {
            while(1);                           // do not load, trap CPU!!
        }
        // configure clock to 16 MHz
        BCSCTL1 = CALBC1_16MHZ;                 // DCO = 16 MHz
        DCOCTL = CALDCO_16MHZ;
        P1DIR |= LED_ALL;
        P1OUT &= ~LED_ALL;
        TIM_TRIG_ADCs_CFG();
        while(1){
        	if(ena){
        		T(1,6);
        		delay_ms(100);
        	}
        return 0;
    }
    }
    
    #pragma vector=TIMER0_A0_VECTOR
    __interrupt void Timer_A00 (void)
    {
    
        if((!((++timerCount)%96))){
            T(1,0);
            if(++tc1==8){
            	ena =1 ;
                __bic_SR_register_on_exit(GIE);
            }
        }
    }
    

  • Let's back up a bit. Can you explain what you are trying to do?

  • I want to make a Timer ISR, after occured,, handle something, I want to stop timer, and go back to main loop, I dont want to use LPM,

  • Then you need only simply turn off the timer in the interrupt handler. TA0CTL=0;
  • Why do you have a return 0; inside the while-loop?
  • >handle something, I want to stop timer, and go back to main loop, I dont want to use LPM,

    Why not LPM0?, it stops main.c in its track waiting for a ISR to tell it to keep going.
    Does that not sound what you want?

    If you want cooperative-multitasking,
    make a event machine in main that only go to lpm0 if all events are 0, use union to check all 16bits in one word.
    and make 3 event share a free-running (continuous) timer by grabbing T0AR on the fly as a starting point for itself.

    //╞════════════════════════════ TA0 ISR ══════════════════════════════════════╡  
    #pragma vector=TIMER0_A0_VECTOR			// Timer A0_0 interrupt service routine
    __interrupt void Timer_A0 (void)                 // TA0CCR0 CCIFG
    {  	   		
            event.alert = 1;                         // optional flag set for: ALERT
            TA0CCTL0 = 0;                            // one time shoot, turn off irq
            __bic_SR_register_on_exit(LPM0_bits);
    }

**Attention** This is a public forum