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.

Bliking a LED every 500ms with timer interrupt

Other Parts Discussed in Thread: MSP430G2553

Hi, people I need some help,I do this code:

include <msp430g2553.h>/*MCU */
#define LED_VERMELHA    BIT0
int SS = 0;
int main(void){
   WDTCTL = WDTPW + WDTHOLD;
P1DIR |= (LED_VERMELHA);
   P1OUT &= ~(LED_VERMELHA);


 if ((CALBC1_1MHZ != 0xFF)  && (CALDCO_1MHZ != 0xFF)) {
   BCSCTL1 = CALBC1_1MHZ;
   DCOCTL = CALDCO_1MHZ;
 }

 TA0CCR0 = 65500;
   TA0CCTL0 = CCIE;
   TA0CTL = TASSEL_2 + MC_1 + ID_3;  
   _BIS_SR(GIE); /*ENABLE INTERRUPT*/


   while(1){
   }
}

#pragma vector=TIMER0_A0_VECTOR
   __interrupt void Timer_A(void) {	/*TIMER0_A0 INTERRUPT SERVICE ROUTINE*/

	SS++;
	P1OUT ^= LED_VERMELHA;

}

I would like to flash the LED every 500ms, but I can not make it work, can someone help me?

  • I don't see you enable TAIE flag in Control Register, though that will also enable overflow ISR
    So better have ISR set up just to clear that flag in case the counter does overflow (should not happen in your setup)

    mov.w #TASSEL_1+MC_2+ID_2+TAIE,&TA0CTL ; use ACLK and Continous up, div by 4, irq

    P.S While(1) I guess you only use for testing as you should use _BIS_SR(CPUOFF+GIE) to go to sleep instead

  • Ant��nio Armando Ferreira said:
    I would like to flash the LED every 500ms, but I can not make it work, can someone help me?

    I just tried your code on a msp430g2553 launchpad and it works for me. What's the specific problem that you're seeing? Is it that the LED doesn't come on at all?

  • well, my idea is each time you start a new cycle the LED blinks. this way I know he's doing interruptions

  • Ant��nio Armando Ferreira said:

    well, my idea is each time you start a new cycle the LED blinks. this way I know he's doing interruptions

    That's exactly what I see happening when I build your code and run it on a launchpad. The red LED connected to P1.0 is initially off, then turns on and off every second.

    What hardware are you running this code on? Is it a msp430g2553 on a MSP-EXP430G2 LaunchPad?

    Which compiler are you using? CCS?

  • Robert, I am usinf CCS, and my hardware is a msp430g2553 launchpad. but nothing happening.

  • Robert, I am usinf CCS, and my hardware is a msp430g2553 launchpad. but nothing happening.

    the idea of ​​using the LED blinking is only to see if it makes interruption because I have an initial variable "int SS = 0;"
    What I'm trying to make is that every time it detects an interruption increment the variable SS. Like SS + +;

  • If you change the top to: P1OUT |= (LED_VERMELHA);

    Does that turn on the LED?

    Have to make sure LED actually works (it does have a jumper)

     

     

  • If you plan to use SS in main later, then it should be declared volatile.

    You run the timer from SMCLK, which is 1MHz. So the timer overflows every 65500/1000000s = 0.0655s. 65500/(1000000/8)s = 0.524. That means your LED would blink with 7.6Hz 0.95Hz, not with 2Hz.

    Besides this, it should work (and does, as Robert confirmed). Are you sure your LED is mounted to P1.0 and in proper direction? (It normally should, but perhaps on your board…). And the jumper is closed?

    Also check whether you inserted the CPU properly. It's easy to bend a pin without noticing.

  • Jens-Michael Gross said:

    You run the timer from SMCLK, which is 1MHz. So the timer overflows every 65500/1000000s = 0.0655s. That means your LED would blink with 7.6Hz, not with 2Hz.

    The TimerA input divider is set to 8, meaning the ISR is called roughly twice per second.

    Also, here's another "outside the box" suggestion: maybe the DCO calibration constants are invalid. The code does check that the values aren't equal to 0xFF (ie erased). That doesn't guarantee that the values are reasonable, however.

    It's unlikely, but maybe the constants have been overwritten with excessively high (but non-0xFF) values.

    Try removing the code that applies the DCO calibration. The default clock speed isn't too much higher than 1MHz, so running uncalibrated should still work well enough to see the LED flash.

**Attention** This is a public forum