Using LFXT1 as clk source

I had been using the internal DCO as clk source.

Now, I would like to use the LFXT1(3MHz) as the source

Here is the code I had used to setup:

//turn on the oscillator via the status register (SR) for configuration
  BCSCTL1 |= XTS;                           // ACLK= LFXT1 = HF XTAL

  do
  {
  IFG1 &= ~OFIFG;                           // Clear OSCFault flag
  for (i = 0xFF; i > 0; i--);               // Time for flag to set
  }
  while ((IFG1 & OFIFG));                   // OSCFault flag still set?

  BCSCTL2 |= SELM_3;

However, code never leaves the do - while loop

If I dont poll for the IFG1 flag, it turns out that the default DCO register value is being used as the clock source frequency

Is there any mistake in the code ?

thanks

There are many possibilities for it not to work.

(1) The MSP430 chip you use may not support 3MHz crystal at LFXT1.

(2) The crystal you use may not be suitable for that MSP430 chip.

(3) The PCB, the MSP430, the crystal, or other components may be defective /out-of-spec.

Can I connect a function generator instead of the crystal and test against this code?

So are you saying you dont see anything wrong in the code?

thanks

Your code will not work for F4xx or F20xx.

My target is F157

Is the crystal connected to pins 8 & 9 or 52 & 53 of F157?

What kind of capacitors (if any) do you use with the crystal?

Do you have specification of the crystal you use?

try wiht this code

//turn on the oscillator via the status register (SR) for configuration
  BCSCTL1 |= XTS;                           // ACLK= LFXT1 = HF XTAL

	_BIC_SR(OSCOFF); 	// turn on XT1 oscillator <----[add this]

  do
  {
  IFG1 &= ~OFIFG;                           // Clear OSCFault flag
  for (i = 0xFF; i > 0; i--);               // Time for flag to set
  }
  while ((IFG1 & OFIFG));                   // OSCFault flag still set?

  BCSCTL2 |= SELM_3;

I have a seemed problem the only thing that a little my code of initialization of the Oscillator is later the following one:

 void InitOsc(void) 
{
	WDTCTL = WDTPW | WDTHOLD;      // Paramos el watchdog timer
	BCSCTL1 |= XTS; 			// XT1 ~ high-frequency
	_BIC_SR(OSCOFF); 		     // turn on XT1 oscillator

	do 					// wait in loop until crystal is stable
	{
		IFG1 &= ~OFIFG;
		for (ii = 0xFFFF; ii > 0; ii--);
	}
	while (IFG1 & OFIFG);

	BCSCTL1 |= DIVA1 | DIVA0; 	// ACLK = XT1 / 8 = 1 MHz
	IE1 &= ~WDTIE; 			     // desactiva WDT int.

	WDTCTL = WDTPW | WDTTMSEL | WDTCNTCL | WDTSSEL | WDTIS1;		// use WDT as timer, flag each. 512 pulses from ACLK
	IFG1 &= ~WDTIFG; 			// clear WDT int. flag
	while ((IFG1 & WDTIFG)!=0); 	    // cuenta 1024 pulsos XT1 

	IFG1 &= ~OFIFG; 		// clear osc. fault int. flag
	DCOCTL |= DCO2 | DCO1 | DCO0;
	BCSCTL1 |= RSEL2 | RSEL1 | RSEL0; 	// MCLK = DCO, 8 MHz  (MCLK=Reloj de la CPU)
}

But to my I have left you begin in the while:

while ((IFG1 & WDTIFG)!=0);

if somebody knows or you go because it happens me this, would thank him that helps me.

Greetings to all and thank you!!