RTC (if MSP Reset) ???

How can i use the timer of the msp as a real time clock.what will

happen to the time if my msp resets.

Regards

If the MSP resets you’ll lose the time.

You’ll want to use some crystal (or other fixed, stable clock input) for at least the clock you’re using to control the timer. The easiest is to stick a 32.768kHz watch crystal on the MSP. Most, if not all, dev boards have this. I’ll assume you need 1 second resolution; if you need more you can adjust the time between interrupts. The way I’ve done this is thus:

  • * Have 3 variables, hours, minutes, seconds

    • Source ACLK off of the 32.768kHz xtal run through the /8 clock divider

    • Source Timer A off of ACLK / 16

    • Have Timer A trigger after 512 counts

    • In the interrupt: add 512 to CCR0. If incrementing the seconds variable brings you to 60 then set it to 0 and increment minutes. If minutes is now 60 set to 0 and increment hours. If hours is now 13 (or 25) set to 1 (or 0)


    I would do it in mspgcc like this:

    volatile char h = 0, m = 0, s = 0;
    
    int main(void)
    {
    ...
      BCSCTL1 |= DIVA0 | DIVA1;
      TACTL  = TASSEL0|TACLR|ID_3;
      CCR0   = 512;
      CCTL0  = CCIE;
      TACTL  |= MC1;
    
      eint();
    ...
    }
    
    interrupt (TIMERA0_VECTOR) INT_TimerA_CCR0(void)
    {
      CCR0 += 512;
      if (++s > 59)
      {
        s = 0;
        if (++m > 59)
        {
          m = 0;
          if (++h > 23)
          {
            h = 0;
          }
        }
      }
    }