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.

Issue Leaving LPM0 with Timer

Other Parts Discussed in Thread: MSP430F5529

I found an example using a simple timer and I am using it with an msp430f5529. I have modified the code so that my LED on P1.0 will blink every 2 sec. I am also using the printf function within the code. I found the code to implement this function on the ti wiki.


I wanted to print a message before I entered the LPM0 and then after the timerISR is completed by exiting LPM0. I used the __bic_SR_register_on_exit(LPM0_bits). There seems to be an issue that arises since it never leaves the low power mode and I never get to see my exit print message.

Below is the code that I have written up:

//******************************************************************************
//  MSP430F552x Demo - Timer0_A5, Toggle P1.0, CCR0 Up Mode ISR, DCO SMCLK
//
//  Description: Toggle P1.0 using software and TA_1 ISR. Timer1_A is
//  configured for up mode, thus the timer overflows when TAR counts
//  to CCR0. In this example, CCR0 is loaded with 50000.
//  ACLK = n/a, MCLK = SMCLK = TACLK = default DCO ~1.045MHz
//	 ACLK = TACLK = 32768Hz
//
//           MSP430F552x
//         ---------------
//     /|\|               |
//      | |               |
//      --|RST            |
//        |               |
//        |           P1.0|-->LED
//
//   Bhargavi Nisarga
//   Texas Instruments Inc.
//   April 2009
//   Built with CCSv4 and IAR Embedded Workbench Version: 4.21
//******************************************************************************
#include <msp430f5529.h>
#include <string.h>
#include <stdio.h>
#include <stdint.h>
#define UART_PRINTF

int fputc(int _c, register FILE *_fp);
int fputs(const char *_ptr, register FILE *_fp);
void main(void)
{
  WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT
  P1DIR |= 0x01;                            // P1.0 output
  /////////////////////////////////////////////////////////////////////////////////

  //Print statement Clock Init

  	// initialize clock module
  	P1DIR |= 0x01;                            // P1.0 output
  	UCSCTL3 |= SELREF__REFOCLK;
  	UCSCTL4 |= SELA__REFOCLK;

  	// initialize Timer_A module
  	TA1CCTL0 = CCIE;                          // CCR0 interrupt enabled
  	TA1CCR0 = 32768;
  	TA1CTL = TASSEL__ACLK + MC__UP + TACLR;   // ACLK, up mode, clear TAR

  	// initialize USCI module
  	P4SEL |= BIT4 + BIT5;                     // P4.4,5 = USCI_A1 TXD/RXD
  	UCA1CTL1 |= UCSWRST;                      // **Put state machine in reset**
  	UCA1CTL1 |= UCSSEL__ACLK;                 // AMCLK
  	UCA1BR0 = 3;                            // 32,768kHz 9600 (see User's Guide)
  	UCA1BR1 = 0;                              // 32,768kHz 9600
  	UCA1MCTL = UCBRS_3;                       // 32,768kHz 9600

  	UCA1CTL1 &= ~UCSWRST;                   // **Initialize USCI state machine**
  ///////////////////////////////////////////////////////////////////////////////
  	
 /////Timer A
  	
  TA0CCTL0 = CCIE;                          // CCR0 interrupt enabled
  TA0CCR0 = 65535;
  TA0CTL = TASSEL_1 + MC_1 + TACLR;         // ACLK, upmode, clear TAR
  printf("Im in");
  __bis_SR_register(LPM0_bits + GIE);       // Enter LPM0, enable interrupts
 // __no_operation();                         // For debugger
  printf("Im out");
  
}

// Timer0 A0 interrupt service routine
#pragma vector=TIMER0_A0_VECTOR
__interrupt void TIMER0_A0_ISR(void)
{
  P1OUT ^= 0x01;                            // Toggle P1.0
  __bic_SR_register_on_exit(LPM0_bits);
}

int fputc(int _c, register FILE *_fp) {
	while (!(UCA1IFG & UCTXIFG))
		;
	UCA1TXBUF = (unsigned char) _c;

	return ((unsigned char) _c);
}

int fputs(const char *_ptr, register FILE *_fp) {
	unsigned int i, len;

	len = strlen(_ptr);

	for (i = 0; i < len; i++) {
		while (!(UCA1IFG & UCTXIFG))
			;
		UCA1TXBUF = (unsigned char) _ptr[i];
	}

	return len;
}

**Attention** This is a public forum