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.

Can TimerA wake up LPM3?

Dear TI and all,

Can TimerA wake up MSP430 from LPM3 to active mode?

I want the MCU in LPM3 mode for save energy and wake up by Timer_A to do something, and so on.

Did I missed some important in my testing code?

/*
* main.c
*/
#include<msp430g2553.h>

#define LED1 BIT0
#define LED2 BIT6

void main(void)
{
	WDTCTL = WDTPW | WDTHOLD;					// Stop watchdog timer
	P1DIR = LED1 + LED2;						// Set pins for LED1, 2 to output
	P1OUT = ~LED1;								// Preload LED1 on, LED2 off

	TACCR0 = 65535;								// Upper limit of count for TAR
	TACTL = MC_1 | ID_3 | TASSEL_2 | TACLR;		// Set up and start Timer A: "up to CCR0" mode, divide clock by 8, clock from SMCLK, clear timer

	for(;;)										// Loop forever
	{
		while((TACTL & TAIFG) == 0)				// Wait for overflow
		{
			__bis_SR_register(LPM3_bits + GIE);
		}
		TACTL &= ~TAIFG; 						// Clear overflow flag
		P1OUT ^= LED1 + LED2;					// Toggle LEDs
	}											// Back around infinite loop
}

B.R.

KJ

  • Kai-Jung Shih said:
    Can TimerA wake up MSP430 from LPM3 to active mode?

    YES

    but in you code is error,

    you set timerA clock as SMCLK (TASSEL_2) but SMCLK in LPM3 is dissabled

    you should set timarA clock as ACLK (TASSEL_1)

    TACTL = MC_1 | TASSEL_1 | TACLR;

    as source ACLK you can use LFXT1CLK (external crystal) or VLOCLK (internal oscylattor)

  • Thanks Lukasz,

    But it still stuck in LED2.

    Is it caused by I did not set ACLK in my code? I just update TASSEL_2 to TASSEL_1 in my code. How can I use LFXT1CLK or VLOCLK in my code?

    Lukasz said:

    as source ACLK you can use LFXT1CLK (external crystal) or VLOCLK (internal oscylattor)

    Further, the CCS tell me advices in line 20 and 25:

    #1528-D (ULP 3.1) Detected flag polling using TAIFG. Recommend using an interrupt combined with enter LPMx and ISR

    #1540-D (ULP 11.2) Assignment of higher bits (constants) to "P1OUT" within a loop. Recommend using lower 4 bits to allow use of constant generators

    Can you tell me how to fix these?

    B.R.

    KJ

  • becouse you sleeping you mc

    __bis_SR_register(LPM3_bits + GIE);

    but never wake up,

    one moment I fix you code,

  • Hi,

    as I see also in your code, you are not activating any interrupt (TAIE bit in TACTL or CCIE bit in TACCTLx). I would suggest to download the code examples: http://www.ti.com/lit/zip/slac485, and you can find a lot of Timer_A examples there.

  • below i pasted you code with few modyfication ( I add interrupts)

    
    /*
    * main.c
    */
    #include<msp430g2553.h>
    #define LED1 BIT0
    #define LED2 BIT6
    
    void main(void)
    {
        WDTCTL = WDTPW | WDTHOLD;                   // Stop watchdog timer
        P1DIR = LED1 + LED2;                        // Set pins for LED1, 2 to output
        P1OUT = ~LED1;                              // Preload LED1 on, LED2 off
                           
        TACCTL0 = CCIE;    				// CCR0 interrupt enabled                       
        TACCR0  = 65535- 1;				// Upper limit of count for TAR
    
    
        TACTL = MC_1 | TASSEL_1 | TACLR;            // Set up and start Timer A: "up to CCR0" mode, divide clock by 8, clock from SMCLK, clear timer
       
        for(;;)                                     // Loop forever
        {
            __bis_SR_register(LPM3_bits + GIE);
    
            P1OUT ^= LED1 + LED2;                   // Toggle LEDs
        }                                           // Back around infinite loop
    }
    
    // Timer A0 interrupt service routine
    #pragma vector=TIMER0_A0_VECTOR
    __interrupt void Timer_A (void)
    {
      __bic_SR_register_on_exit(LPM3_bits);
    }

    ACLK will be set automaticly,

    (external oscyllator or if not exist then internal oscyllator vlo)

  • Thanks Lukasz, it works.

    But When I add line 31 to 35 (the Timer A0 interrupt service routine) to the end of main.c of "0456.ez430_TRF7970_UART_Card_Emulation_Type_A_or_B" from thread TRF7970A EVM sample code interfacing with on board MSP430F2370. I got a compilation failure:

    fatal error #10192: Failed linktime optimization

    I am not sure how to resolve. Can you or someone can help me.

    Thanks.

    B.R.

    KJ

  • in folder hardware you have files trf796xBoosterPack


    do you use this files in you project ?

    maybe are added into projekct ?

    if are added and you dont use it in project, then remove this files from project,

  • Dear Lucasz,

    Yes, I use files trf796xBoosterPack in my project.

    I use Import CCS Project for this and setting is ready in Project -> Properties -> Build -> MSP430 Compiler -> Include Options. It compiled and worked fine before I add the Timer A0 interrupt service routine.

  • TimerA0 interrupt service routine is defined in trf796xBoosterPack

    #pragma vector=TIMER0_A0_VECTOR
    __interrupt void
    timerHandler(void)
    {
        u08_t irq_status[4];
    
        STOP_COUNTER;
    
        irq_flag = 0x02;
    
        Trf796xReadIrqStatus(irq_status);
    
        *irq_status = *irq_status & 0xF7;                // set the parity flag to 0
    
        if(*irq_status == 0x00 || *irq_status == 0x80)
        {
            i_reg = 0x00;                                // timer interrupt
        }
        else
        {
            i_reg = 0x01;
        }
    
    }

    because I ask you abut usage of trf796xBoosterPack

    so you cant duplicate service routine,

    for you purpose you must use another service routine

    ( I see that timerA1 is free )

     

     

  • Dear Lukasz,

    Thanks for find out the problem part of my code, it's so shamed.

    For testing Timer_A1 ISR, I modified for the line 28 below. But it result in LED2 light up and dose not toggle into LED1. Am I got something wrong?

    /*
    * main.c
    */
    #include<msp430g2553.h>
    
    #define LED1 BIT0
    #define LED2 BIT6
    
    void main(void)
    {
        WDTCTL = WDTPW | WDTHOLD;					// Stop watchdog timer
        P1DIR = LED1 + LED2;						// Set pins for LED1, 2 to output
        P1OUT = ~LED1;								// Preload LED1 on, LED2 off
    
        TACCTL0 = CCIE;								// CCR0 interrupt enabled
        TACCR0  = 5535;								// Upper limit of count for TAR
        TACTL = MC_1 | TASSEL_1 | TACLR;			// Set up and start Timer A: "up to CCR0" mode, clock from ACLK, clear timer
    
        for(;;)
        {
            __bis_SR_register(LPM3_bits + GIE);		//
            P1OUT ^= LED1 + LED2;					// Toggle LEDs
        }
    }
    
    // Timer A0 interrupt service routine
    #pragma vector=TIMER0_A1_VECTOR
    __interrupt void Timer_A (void)
    {
      __bic_SR_register_on_exit(LPM3_bits);
    }
    

  • hi,

    you didn't change configuration (in isr declaration also was mistake)

    below I paste you fixed code (Timer1 configuration), check it

    /*
    * main.c
    */
    #include<msp430g2553.h>
    #define LED1 BIT0
    #define LED2 BIT6
    
    void main(void)
    {
        WDTCTL = WDTPW | WDTHOLD;                   // Stop watchdog timer
    
        P1DIR =   LED1 + LED2;                        // Set pins for LED1, 2 to output
        P1OUT =   LED1;                              // Preload LED1 on, LED2 off
        P1OUT &=~ LED2;  
        
        TA1CCTL0 = CCIE;                             // CCR0 interrupt enabled
        TA1CCR0  = 5535;                             // Upper limit of count for TAR
        TA1CTL = MC_1 | TASSEL_1 | TACLR;            // Set up and start Timer A: "up to CCR0" mode, clock from ACLK, clear timer
        
        for(;;)
        {
            __bis_SR_register(LPM3_bits + GIE);     //
            P1OUT ^= LED1 + LED2;                   // Toggle LEDs
        }
    }
    // Timer1 A0 interrupt service routine
    #pragma vector=TIMER1_A0_VECTOR
    __interrupt void Timer_A (void)
    {
      __bic_SR_register_on_exit(LPM3_bits);
    }

  • Lukasz: ACLK will by default try to run from LFXT1. There is no automatic fallback to VLO. If there is no crystal, then LFXT1S_2 needs to be explicitly selected to switch it to VLO, otherwise the timer won’t be clocked.

    Besides this, of course you were right: the original problem was that LPM3 disables SMCLK and the timer didn’t proceed.

  • Hi
    we changing trf796xBoosterPack  code

    in this device/code LPM3 is in use, and ACLK working propertly

    b.r. L.K.

    Kai-Jung Shih said:

    Thanks Lukasz, it works.

    But When I add line 31 to 35 (the Timer A0 interrupt service routine) to the end of main.c of "0456.ez430_TRF7970_UART_Card_Emulation_Type_A_or_B" from thread TRF7970A EVM sample code interfacing with on board MSP430F2370. I got a compilation failure:

    fatal error #10192: Failed linktime optimization

    I am not sure how to resolve. Can you or someone can help me.

    Thanks.

    B.R.

    KJ

**Attention** This is a public forum