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.
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.
**Attention** This is a public forum