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.

MSP430F1222, SMCLK - Changing Source from LFXT1 to DCO on OFIFG

Other Parts Discussed in Thread: MSP430F1232

Hi,

On startup, my code sets the SELS bit so that SMCLK runs from LFXT1 (4MHz). The MCLK is also running from LFXT1.

Timer_A is running off SMCLK.

When I introduce an oscillator fault (open circuit the crystal), execution jumps to NMI_VECTOR. The DCO must be clocking the CPU at this stage.

The NMI ISR clears SELS so that the SMCLK runs off the DCO (which is now clocking the CPU.

SMCLK is output onto P1.4; a scope is attached to this point. Sometimes the clock change occurs, sometimes not.

Are there any subtleties I am missing here? SMCLK rarely runs when its source is changed to DCO.

#pragma vector = NMI_VECTOR
__interrupt void NMI_OFIFG_ISR(void)
{
  if ((IFG1 & OFIFG) != 0) {    /* Switch to DCO. */
    IFG1 &= ~OFIFG;             /* Clear OSCFault flag. */
    TA0CTL = 0;                 /* Stop Timer_A before changing clock source. */
    BCSCTL2 &= ~SELS;           /* Change SMCLK source to DCO. */
    BCSCTL2 = SELM_0 + DIVM_0 + DIVS_0;     /* Run CPU off DCO if XTAL fails. */
    TA0CTL = TASSEL_2 + ID_2 + MC_2; /* Run timer off DCO (SMCLK) if XTAL fails. */
    
    IFG1 &= ~OFIFG;             /* Clear OSCFault flag. */
    LPM3_EXIT;
  }
}


Cheers, Nick.

  • Hi Nick,

    The behavior you described is exactly the Clock Module Fail-Safe Operation described in Section 4.2.6 of the user's guide www.ti.com/.../slau049f.pdf
    The NMI interrupt service routine tests if the oscillator fault occurs, SMCLK is automatically switched to DCO for its clock source if the fault is detected. The XT_OscFault signal becomes active immediately, remains active until the oscillator is re-started, and becomes inactive approximately 50 µs after the oscillator re-starts.
    Furthermore, to switch SMCLK back to LFXT1, follow the section on Sourcing MCLK from a Crystal
    1) Switch on the crystal oscillator
    2) Clear the OFIFG flag
    3) Wait at least 50 µs
    4) Test OFIFG, and repeat steps 1-4 until OFIFG remains cleared.

    Sincerely,
    Sean
  • Hi Sean,

    The problem I have is that the SMCLK is NOT being sourced from the DCO. In my NMI service routine, I am trying to set the SMCLK to run off the DCO but it isn't working.
    The document section you refer to discusses how MCLK (not SMCLK) is automatically sourced from the DCO; this is indeed happening.

    I think you might have misread my original post.

    Regards,
    Nick.
  • I'm beginning to think there is no answer to this question other than a fault exists on the chip (MSP430F1232).
    There was a similar question asked on this forum and it was also left unanswered. (Someone was trying to switch the SMCLK back to run off the DCO.)

    The one answer given was completely misinterpreting what I had asked...
  • Hi Nick,

    I apologize for the extremely late response, to help clarify the issue of the SMCLK not running when sourced from DCO, can you output SMCLK to a pin and verify it matches the set DCO frequency, or if the SMCLK not sourcing from DCO. Refer to page 2 of the datasheet for the SMCLK output pin.
    www.ti.com/.../msp430f1232.pdf

    Sincerely,
    Sean

**Attention** This is a public forum