我们使用的MSP430FR2422 在 P2.0,P2.1 两个脚位接了 外部晶振,经检测,晶振的两侧有1V的电压,软件部分直接参照 msp430fr243x_CS_04.c,但是软件烧录进去之后,晶振没有起振。
我的main 函数如下所示,请教一下code是否有问题,如何才能让晶振正常起振,晶振没有起振的大体原因有那些。
int main(void)
{
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
P2SEL0 |= BIT0 | BIT1; // set XT1 pin as second function
do
{
CSCTL7 &= ~(XT1OFFG | DCOFFG); // Clear XT1 and DCO fault flag
SFRIFG1 &= ~OFIFG;
}while (SFRIFG1 & OFIFG); // Test oscillator fault flag
__bis_SR_register(SCG0); // disable FLL
CSCTL3 |= SELREF__XT1CLK; // Set XT1CLK as FLL reference source
CSCTL1 = DCOFTRIMEN | DCOFTRIM0 | DCOFTRIM1 | DCORSEL_0;// DCOFTRIM=3, DCO Range = 1MHz
CSCTL2 = FLLD_0 + 30; // DCODIV = 1MHz
__delay_cycles(3);
__bic_SR_register(SCG0); // enable FLL
Software_Trim(); // Software Trim to get the best DCOFTRIM value
CSCTL4 = SELMS__DCOCLKDIV | SELA__XT1CLK; // set ACLK = XT1CLK = 32768Hz
// DCOCLK = MCLK and SMCLK source
// Now that osc is running enable fault interrupt
SFRIE1 |= OFIE;
P1DIR |= BIT4; // set MCLK SMCLK and LED pin as output
PM5CTL0 &= ~LOCKLPM5; // Disable the GPIO power-on default high-impedance mode
// to activate previously configured port settings
while(1)
{
__delay_cycles(1000000);
// Toggle P1.0 using exclusive-OR
P1OUT ^= BIT4;
// Delay for 500000*(1/MCLK)=0.5s
}
}