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.

setup clocks MSP4305137



I'm currently attempting to set up my clocks for my system and I'm getting a little confused I believe my system is set up to run SMCLK at 4MHz, but when using the USCI it would appear that SMCLK is running at 16MHz.

I use the following code to set up my clocks:

			UCSCTL3 |= SELREF_0;                      // Set DCO FLL reference = XT1
			UCSCTL4 |= SELA_0+SELS_4+SELM_4;          // Set ACLK = XT1, SMCLK = DCOCLK & MCLK = DCOCLK

			__bis_SR_register(SCG0);		  // Disable the FLL control loop
			UCSCTL0 = 0x0000;                         // Set lowest possible DCOx, MODx
			UCSCTL1 = DCORSEL_5;                      // Select DCO range 2.5-6MHz operation
			UCSCTL2 = FLLD_1 + 249;                   // Set DCO Multiplier for 4MHz
								  // (N + 1) * FLLRef = Fdco
								  // ((249 + 1) * 32768)/2 = 4MHz
								  // Set FLL Div = fDCOCLK/2
			__bic_SR_register(SCG0);		  // Enable the FLL control loop

			// Worst-case settling time for the DCO when the DCO range bits have been
			// changed is n x 32 x 32 x f_MCLK / f_FLL_reference. See UCS chapter in 5xx
			// UG for optimisation.
			// 32 x 32 x 4 MHz / 32,768 Hz = 125000 = MCLK cycles for DCO to settle
			__delay_cycles(125000); 
		/*****************************************************************************************************/
			// Loop until XT1,XT2 & DCO fault flag is cleared
			do
			{
				UCSCTL7 &= ~(XT2OFFG + XT1LFOFFG + XT1HFOFFG + DCOFFG);
				// Clear XT2,XT1,DCO fault flags
				SFRIFG1 &= ~OFIFG;                      // Clear fault flags
			} while (SFRIFG1 & OFIFG);                  // Test oscillator fault flag

However inorder to get 9600 baud out of the micro I have to use the following settings:

    UCA0CTL1 = UCSSEL_2;
    UCA0BR0 = 0x82;
    UCA0BR1 = 0x06;
    UCA0MCTL = UCBRS_6 + UCBRF_0

which would imply that SMCLK is running at 16MHz.

XT1 is connected to an external crystal at a speed of 32768KHz. is there something wrong in the way I am setting up my clock?

  • george,

    I assume you are using 32768 kHz at XT1. Anyway, i quickly checked your code, and it seems the setting is correct for 4MHz. Have you tried to output the SMCLK clock to an output pin and see whether the SMCLK frequency is correct? Most of MSP430 device has this option to output clock signals (ACLKD, SMCLK) to an output pin.

  • Leo Hendrawan said:

    I assume you are using 32768 kHz at XT1.

    Yes that is correct.

    Leo Hendrawan said:

    Have you tried to output the SMCLK clock to an output pin

    Yes I have, I had the thought after my inital post. However before I did that I discovered the line

    UCSCTL4=SELA_0|SELS_3|SELM_3;

    which would run after the code I posted earlier. Removing that line and then outputting SMCLK on a pin I found that the frequency it was running at was 8MHz

    measuring it on a scope I am getting

  • george,

    the math of your setting is is that DCO freq = (249+1) * 32 khZ = ~8MHz. This will be the frequency of DCO, while DCOCLKDIV value depends on the FLLD. If you set as FLLD_1 this means fDCOCLKDIV = fDCO/2. Please refer to the UCSCTL2 register description.

**Attention** This is a public forum