Jump to content
43oh

MSP430G2553 Timer1 interrupts trigger in debug, but don't when not in debug.


Recommended Posts

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;
}

 

 

Link to post
Share on other sites

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;
}

Link to post
Share on other sites

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 :smile:) 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.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...