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.

Using XT2 as a source for SMCLK and MCLK

Other Parts Discussed in Thread: CC430F5137

Hello every one,

I am using CC430F5137 on Olimax Board. i want to source my SMCLK from XT2 for that purpose i am using the code which is given in the TI example but didnot get one thing that why we are using while(1) in the end line.


#include <msp430.h>

int main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer

PMAPPWD = 0x02D52; // Get write-access to port mapping regs
P2MAP2 = PM_SMCLK; // Map SMCLK output to P2.2
P2MAP4 = PM_MCLK; // Map MCLK output to P2.4
PMAPPWD = 0; // Lock port mapping registers

P2DIR |= BIT2 + BIT4; // MCLK, SMCLK set out to pins
P2SEL |= BIT2 + BIT4; // P2.2, P2.4 for debugging

UCSCTL6 &= ~XT2OFF; // Enable XT2
UCSCTL3 |= SELREF_2; // FLLref = REFO
// Since LFXT1 is not used,
// sourcing FLL with LFXT1 can cause
// XT1OFFG flag to set

// ACLK=REFO,SMCLK=DCO,MCLK=DCO
UCSCTL4 = SELA__REFOCLK + SELS__DCOCLKDIV + SELM__DCOCLKDIV;

// Loop until XT1,XT2 & DCO stabilizes
do
{
UCSCTL7 &= ~(XT2OFFG + XT1LFOFFG + DCOFFG);
// Clear XT2,DCO fault flags
SFRIFG1 &= ~OFIFG; // Clear fault flags
}while (SFRIFG1&OFIFG); // Test oscillator fault flag

UCSCTL4 |= SELA__REFOCLK + SELS__XT2CLK + SELM__XT2CLK; // SMCLK=MCLK=XT2

while(1); // Loop in place
}

  • This code just configures P2.2 and P2.4 to output the clock signals. There isn't anything else to do, so it goes into an infinite loop.
  • Thanks for your reply, so if i don't use this while loop then whats happened? it configures XT2 to SMCLK / MCLK for only one time ? or it configures permanently until i change it to other source.
  • Hello,

    P2.2 and P2.4 are set to outputs for measuring the MCLK and SMCLK with an oscilloscope for example.

    You can not source an external CLK signal to these ports.

    For the FLL you select REFO as source.

    -- UCSCTL3 |= SELREF_2; // FLLref = REFO --

    Then you define the CLK sources for MCLK, SMCLK, ACLK.

    -- UCSCTL4 = SELA__REFOCLK + SELS__DCOCLKDIV + SELM__DCOCLKDIV --

    This is OK, but in the following oscillator fault loop the XT2 startup will not be checked.

    You need to use the code -- UCSCTL4 |= SELA__REFOCLK + SELS__XT2CLK + SELM__XT2CLK; // SMCLK=MCLK=XT2 --

    instead of -- UCSCTL4 = SELA__REFOCLK + SELS__DCOCLKDIV + SELM__DCOCLKDIV --

    in this case your XT2 startup will be checked in the fault loop.

    Regards,

    Manuel

  • If you don't use the while loop, execution falls out of the end of the main() function. This is not supposed to happen in an embedded application. The actual result depends on the C startup code of your compiler; it might go into an infinite loop itself, or shut down the CPU, or reset it.

**Attention** This is a public forum