I am a programmer working on a customized board equipped with MSP430F5151.
We have an 12MHz oscillator on XT1. My intention is to use this oscillator as my MCLK and SMCLK for testing purpose.
I discovered a behavior that I don't understand.
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
Clock_Init();
GPIOnEINT_Init();
Timer_Init();
__enable_interrupt();
for(;;);
}
void Clock_Init(void)
{
// to support 12MHz
SetVcoreUp (0x01);
// Configure XT1
PJSEL |= BIT4+BIT5; // Port select XT1
UCSCTL6 |= XTS; // HF
UCSCTL6 &= ~(XT1DRIVE1); // 12MHz
UCSCTL6 &= ~(XT1OFF); // XT1 On
// Configure DCO
// __bis_SR_register(SCG0); // Disable the FLL control loop
// UCSCTL0 = 0x0000; // Set lowest possible DCOx, MODx
// UCSCTL3 = SELREF1; // Set RefClk
// __bic_SR_register(SCG0); // Enable the FLL control loop
__delay_cycles(375000);
// Loop until XT1 & DCO fault flag is cleared
do
{
UCSCTL7 &= ~(XT1LFOFFG + XT1HFOFFG + DCOFFG);
// Clear XT1, DCO fault flags
SFRIFG1 &= ~OFIFG; // Clear fault flags
} while ( UCSCTL7 & (XT1LFOFFG + XT1HFOFFG) ); // Test oscillator fault flag
UCSCTL4 = SELA0; // Configure Clock Source
}
void Timer_Init(void)
{
TA0CTL = TASSEL__SMCLK + MC__CONTINOUS;
TA0CCR0 = 12000;
TA0CCTL0 = CCIE; // Capture/compare interrupt enable
}
#pragma vector=TIMER0_A0_VECTOR
__interrupt void Timer0_A0(void) /* TA0CCR0 CCIFG0 */
{
TA0CCR0 += 12000;
one_ms_counter++;
if ( ( one_ms_counter % 500 ) == 0 ) P3OUT ^= (1u<<1); // Blink LED for 1 second interval
}
The above code give me an expected result, a blinking LED with 1 second interval.
But if I do not Clear OFIFG, the LED blinks with around 5 second interval.
I don't understand why, and worry about such a situation.