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.

MSP430 Making an RTC and timed LED but apparently made a "busy wait"

Other Parts Discussed in Thread: MSP430G2553

Hi,

Im trying to count time on an artificial RTC (Im using a MSP430G2553 which doesnt have an inbuilt one) and simultaneously blink an LED at 5 second intervals. 

Eventually I want to count the number of pulses I get in a square wave and store it with a timestamp from this RTC and thought the LED step would at least show me if my RTC is working. 

I'm very VERY new to this (first ever embedded C) and I'm struggling with it a lot. This code is the product of days worth of researching and its still not working.

#include <msp430g2553.h>

#include "RTC.h"

volatile unsigned

int RTC_Counter = 0; // TIMERA0

interrupt service routine

#pragma vector=TIMERA0_VECTOR __

interrupt void Timer_A (void)

{

incrementSeconds();

RTC_Counter ++;

if(RTC_Counter > 5)

{

P1OUT = 0b00000001;

RTC_Counter = 0;

}

else {

LPM3_EXIT;

}

}

void init()

{

WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer

setTime(0x12, 0 , 0, 0); //intialise to 12:00:00AM

CCR0 = 32768 - 1;

P1DIR |= 0x00; //P1.0 output direction

TACTL = TASSEL_1+MC_1; //ACLK, UPMODE

CCTL0 |= CCIE; //ENABLE

CCRO INTERUPT _EINT(); //Enable Global interrupts

}

void main(void)

{

init();

while(1)

{

LPM3; //Enter Low power mode

}

}

  • This code is unreadable; edit the question and use the "Insert code" button.

    To make a pin an output, you have to set the bit in PxDIR.

  • P1DIR |= 0x00 doesn't do anything, as it sets all bits in P1DIr that are set in 0x00 (which are none).
    To switch P1.0 to output, you need to set bit 0 of P1DIR to 1:
    P1DIR |= 0x01;

    Also, your ISR counts to 6. but in every case it does NOT set P1.0 to 1 (you should rather toggle P1.0 by using P1OUT ^= 0x01), it exits LPM3. So after the first interrupt, it wakes up, cycles once through the while(1) and goes back to sleep for the next second, while on the interrupt it switches the output on, it does not wake up. Not exactly busy-waiting (which you won't notice on the debugger, as debugging is so slow that it makes no difference), but surely not the intended behavior.

**Attention** This is a public forum