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.
So I'm just experimenting with getting an interrupt to work correctly. My code is:
#include "msp430fw427.h"
#include "intrinsics.h"
#define LED1 BIT3
#define LED2 BIT4
void main (void)
{
WDTCTL = WDTPW|WDTHOLD;
P2OUT = ~LED1;
P2DIR = LED1|LED2;
TACCR0 = 49999;
TACCTL0 = CCIE;
TACTL = MC_1|ID_3|TASSEL_2|TACLR;
__enable_interrupt();
for (;;)
{
}
}
#pragma vector = TIMER1_A0_VECTOR
__interrupt void TA0_ISR(void)
{
P2OUT ^= LED1|LED2; // set timer status flag
}
Instead of toggling the LEDs; the only thing that is happening is LED1 is staying on while the other stays off. Any ideas why they aren't toggling?
Thanks,
If you set a breakpoint in the ISR does the PC reach it? If not then I suspect your interrupt vector definition may not agree with your timer setup. The following is from the FW427 header file:
#define TIMER0_A1_VECTOR (5 * 2u) /* 0xFFEA Timer0_A CC1-2, TA0 */
#define TIMER0_A0_VECTOR (6 * 2u) /* 0xFFEC Timer0_A CC0 */
#define TIMER1_A1_VECTOR (12 * 2u) /* 0xFFF8 Timer1_A CC1-4, TA1 */
#define TIMER1_A0_VECTOR (13 * 2u) /* 0xFFFA Timer1_A CC0 */
/* Alternate Names */
#define TIMERA1_VECTOR TIMER0_A1_VECTOR
#define TIMERA0_VECTOR TIMER0_A0_VECTOR
Try using "TIMER0_A0_VECTOR " instead of TIMER1_A0...
Hi Brock,
only made some minor modifications to the app to make it usable for eZ430-RF2500 (LED connections, different MCU).
Result: IT WORKS PERFECTLY!
Question: What is your Main clock (in MHz)? Did you configure your clocks?
Rgds
aBUGSworstnightmare
#include "msp430f2274.h"
#include "intrinsics.h"
/*-----------------------------------------------------------------------------
//
Compiler switches
// used as:
// #ifdef SOMETHING
//
... ; additional code lines for test version only
//
#endif
// ONLY USE ONE AT AT TIME!!!!!!!!!!!!!!!!
//---------------------------------------------------------------------------*/
//#define
SLOW // slow MCLK settings
#define
FAST // fast MCLK settings
// defines
for eZ430RF2500T
// LED were connected to PORT1
#define LED1 BIT0
#define
LED2 BIT1
void main (void)
{
// disable watchdog timer
//------------------------
WDTCTL = WDTPW + WDTHOLD;
// Stop WDT
// clock setting
//------------------------
#ifdef FAST
DCOCTL = CALDCO_16MHZ; // Set DCO to
16MHz
BCSCTL1 = CALBC1_16MHZ; // MCLC = SMCLK =
DCOCLK = 16MHz
#endif
#ifdef SLOW
DCOCTL =
CALDCO_1MHZ; // Set DCO to 1MHz
BCSCTL1 =
CALBC1_1MHZ; // MCLC = SMCLK = DCOCLK = 1MHz
#endif
BCSCTL1 |= DIVA_0; // ACLK = ACLK/1
BCSCTL3 = LFXT1S_2; // LFXT1 = ACLK = VLO = ~12kHz
BCSCTL3 &= ~LFXT1OF; // clear LFXT1OF flag, 0
P1OUT = ~LED1;
P1DIR = LED1|LED2;
TACCR0 = 49999;
TACCTL0 = CCIE;
TACTL = MC_1|ID_3|TASSEL_2|TACLR;
__enable_interrupt();
for (;;)
{
__no_operation();
}
}
#pragma vector = TIMERA0_VECTOR
__interrupt void TA0_ISR
(void)
{
P1OUT ^= LED1|LED2;
}
Thanks guys; this stuff is going over my head a bit so I'm gonna chill out a bit and read up on clock configurations/etc. Pretty sure that's why my interrupt isn't working. Just gotta work it out.
hi aBUGSworstnightmare, the code you posted works, but once i inserted the following code (using the definitions from the files slaa325a.zip):
if (a>=2)
{
TI_CC_LED_PxOUT ^= TI_CC_LED2;
a=0;
}
a++;
// __no_operation(); // commenting this in my code
in the for(;;) loop, then the led defined by TI_CC_LED1 blinks ok using the timer interruption, but TI_CC_LED2 doesn't blink at all.
what am i setting wrong?
i am trying to fix another problem i have, and i think the solution for this will help me.
beforehand, thanks a lot.
regards,
gustavo
If TI_CC_LED2 equals LED2 in the posted code, and TI_CC_LED_PxOUT equals P1OUT, then just inserting the above code will toggle the LED2 on every second loop, which is at app. MCLK/20. So the LED is blinking with ~25kHz per MHz MCLK. I'd say it is a bit too fast for the naked eye. Perhaps an ultra-high-speed camera might see something? (or a scope)
thanks for the answer, you are right, it's too fast for the naked eye. what i meant to write in the code was something higher than 2 for the 'if' condition.
anyway, i have increased that condition to 25000 (and checking the periods of the clock) and just now it is possible observe the blinking.
**Attention** This is a public forum