mike1994 0 Posted April 9, 2013 Share Posted April 9, 2013 Hi, I'm using the MSP430G2553. My code below is supposed to toggle pin1.5 based on Timer1. It works fine when I am in debug mode, but if I exit debug and hit the reset button on the launchpad, it doesn't toggle pin1.5 (as per my coding requests). I was wondering why my Timer1 interrupts does not fire if I am not in debug mode? /* * main.c */ #include "msp430g2553.h" static int TESTSWITCH = BIT3; void main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop WDT BCSCTL1 = CALBC1_8MHZ; DCOCTL = CALDCO_8MHZ; P1DIR &= ~TESTSWITCH; P1OUT |= TESTSWITCH; P1REN |= TESTSWITCH; //Enable internal pull up register P1IES |= TESTSWITCH; P1IFG &= ~TESTSWITCH; P1IE |= TESTSWITCH; //Enable switches for interrupts P1DIR |= BIT5; P1OUT &= ~BIT5; TA1CCR0 = 6000; // Count limit (16 bit) TA1CCTL0 = CCIE; // Enable counter interrupts, bit 4=1 TA1CTL = TASSEL_1 + MC_1; __bis_SR_register(LPM0_bits + GIE); // Enter LPM0, interrupts enabled } #pragma vector=PORT1_VECTOR __interrupt void Port_1(void) { P1IE &= ~TESTSWITCH; P1OUT ^= BIT5; P1IFG &= ~TESTSWITCH; P1IE |= TESTSWITCH; } #pragma vector=TIMER1_A0_VECTOR // Timer1 A0 interrupt service routine __interrupt void Timer1_A0(void) { P1OUT ^= BIT5; } Quote Link to post Share on other sites
ILAMtitan 86 Posted April 10, 2013 Share Posted April 10, 2013 Mike1994, I ran your code on a launchpad I have laying around and it worked just fine for me. I did change the output to pin 1.6 to match the hardware though. Try power cycling the board rather than just using the reset button; there might be a problem with your hardware. mike1994 and bluehash 2 Quote Link to post Share on other sites
ike 53 Posted April 10, 2013 Share Posted April 10, 2013 Hello my dear friend mike1994. I hope that this code solve your issue. Have a nice day. #include "msp430g2553.h" static int TESTSWITCH = BIT3; static int MAGIC_8MHz = ' '; void main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop WDT DCOCTL = CALDCO_8MHZ; BCSCTL1 = CALBC1_8MHZ; BCSCTL3 = MAGIC_8MHz; P1DIR &= ~TESTSWITCH; P1OUT |= TESTSWITCH; P1REN |= TESTSWITCH; //Enable internal pull up register P1IES |= TESTSWITCH; P1IFG &= ~TESTSWITCH; P1IE |= TESTSWITCH; //Enable switches for interrupts P1DIR |= BIT6; P1OUT &= ~BIT6; TA1CCR0 = 6000; // Count limit (16 bit) TA1CCTL0 = CCIE; // Enable counter interrupts, bit 4=1 TA1CTL = TASSEL_1 + MC_1; __bis_SR_register(LPM0_bits + GIE); // Enter LPM0, interrupts enabled } #pragma vector=PORT1_VECTOR __interrupt void Port_1(void) { P1IE &= ~TESTSWITCH; P1OUT ^= BIT6; P1IFG &= ~TESTSWITCH; P1IE |= TESTSWITCH; } #pragma vector=TIMER1_A0_VECTOR // Timer1 A0 interrupt service routine __interrupt void Timer1_A0(void) { P1OUT ^= BIT6; } mike1994 and Rickta59 2 Quote Link to post Share on other sites
tripwire 139 Posted April 10, 2013 Share Posted April 10, 2013 Ooops, I hadn't noticed that you're using TASSEL_1 (aka ACLK) as the timer source! ACLK is sourced from the LF crystal oscillator by default. Ike's post above includes the (quite bewildering ) lines: static int MAGIC_8MHz = ' '; ... BCSCTL3 = MAGIC_8MHz; Which are equivalent to: BCSCTL3 = LFXT1S_2; // ' ' == 0x20 == LFXT1S_2 That changes ACLK to be sourced from the VLO instead of the crystal oscillator. If that change fixes the problem, then the crystal is failing to start up correctly when you're running without the debugger attached. It's worth taking a look at this thread, which describes a similar issue and includes source for a test program to check the crystal oscillator. mike1994 1 Quote Link to post Share on other sites
mike1994 0 Posted April 12, 2013 Author Share Posted April 12, 2013 Thank you. Changing to VLO worked! Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.