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.
Hi,
Below is the code to configure Timer0 on MSP430G2553 in up mode. On interrupt (i.e when timer value rolls over), I am toggling the LED. LED toggles when compiled and flashed with IAR but it doesnt work when compiled and flashed with CCS. Please help me with this issue.
#include <msp430.h>
/*
* main.c
*/
int main(void)
{
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
P1DIR |= 0x01;
TACTL=0x152; // Select Clock source, clock divider and enable timer interrupt
TACCTL0=CCIE; // Select compare mode and enable compare interrupt.
TACCR0=32768; // Timer Value register.
_EINT(); // Enable Global Interrupts.
for(;;)
{
}
}
#pragma vector=TIMER0_A0_VECTOR
__interrupt void TIMER0_ISR (void)
{
P1OUT ^= 0x01; // Toggle the LED each time the timer rolls over after max value.
}
Thanks and regards,
Shivakumar V W
What does the object code look like when compiled with CCS?
Is the for (,,){} endless loop optimized out?
You've set the TAIE bit in TACTL, which enables the TAIFG interrupt request. You've also set CCIE in TACCTL0, which enables the CCIFG interrupt request.
When TAR counts to the value in TACCR0, the TACCTL0.CCIFG flag will be set and that will result in the TIMER0_A0_VECTOR being called. That will toggle the state of P1.0 as you'd expect.
On the next tick, TAR will "count" from the value in TACCR0 to zero, and TACTL.TAIFG will be set. That will cause the processor to try to run the TIMER0_A1_VECTOR which is not defined. On recent versions of CCS this will result in the trap ISR being called, and that will put your program into an infinite loop. I'm not sure what's happening on IAR, but it's possible that the MCU is resetting and restarting the program from the top. That would result in it looking like it was working correctly, as the IO output state is maintained across resets.
Try changing the program to set TACTL = TASSEL_1 | ID_1 | MC_1, and it should work on both IAR and CCS.
**Attention** This is a public forum