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.

XTAL cannot clear CS_clearAllOscFlagsWithTimeout

Other Parts Discussed in Thread: MSP430FR2355, MSP430WARE

Hi all,

running just simple demo on MSP430FR2355 to test XTAL (20MHz) configuration finishes in NMI.

Could someone give a hint... why it would go to NMI?

Sample code:

void SETUP_EXTERNAL_XTAL(){

bool status;


//Initializes the XT1 and XT2 crystal frequencies being used
CS_setExternalClockSource(CS_XT1_CRYSTAL_FREQUENCY);

//Initialize XT1. Returns STATUS_SUCCESS if initializes successfully
status = CS_turnOnXT1HFWithTimeout(CS_XT1_DRIVE_0, CS_XT1_HFFREQ_16MHZ_24MHZ,CS_XT1_TIMEOUT);

//Select XT1 as ACLK source
//CS_initClockSignal(CS_ACLK,CS_XT1CLK_SELECT,CS_CLOCK_DIVIDER_4);

//Select XT1 as SMCLK source
CS_initClockSignal(CS_SMCLK,CS_XT1CLK_SELECT,CS_CLOCK_DIVIDER_1);

//clear all OSC fault flag
CS_clearAllOscFlagsWithTimeout(10000); // 1000

//Enable oscillator fault interrupt
SFR_enableInterrupt(SFR_OSCILLATOR_FAULT_INTERRUPT);

}

void main(void)
{

//Stop Watchdog Timer
WDT_A_hold(WDT_A_BASE);

SETUP_PIN__EXTERNAL_XTAL();

//ACLK set out to pins
GPIO_setAsPeripheralModuleFunctionOutputPin(
GPIO_PORT_P1,
GPIO_PIN1,
GPIO_SECONDARY_MODULE_FUNCTION
);
//SMCLK set out to pins
GPIO_setAsPeripheralModuleFunctionOutputPin(
GPIO_PORT_P3,
GPIO_PIN4,
GPIO_PRIMARY_MODULE_FUNCTION
);
//MCLK set out to pins
GPIO_setAsPeripheralModuleFunctionOutputPin(
GPIO_PORT_P3,
GPIO_PIN0,
GPIO_PRIMARY_MODULE_FUNCTION
);


PMM_unlockLPM5();


SETUP_EXTERNAL_XTAL();

// Enable global interrupt
__bis_SR_register(GIE);

while(1){

// Do nothing

}

#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=UNMI_VECTOR
__interrupt
#elif defined(__GNUC__)
__attribute__((interrupt(UNMI_VECTOR)))
#endif
void NMI_ISR(void)
{
uint16_t status;

do {
// If it still can't clear the oscillator fault flags after the timeout,
// trap and wait here.
status = CS_clearAllOscFlagsWithTimeout(1000);
} while(status != 0);
}

  • Hi Nikola,

    I have a few questions:

    1. What XTAL are you using? Are you providing the required effective load capacitance with external caps? More details and calculations for this can be found in our app note linked below. You will want to look at section 2.1

    http://www.ti.com/lit/an/slaa322d/slaa322d.pdf

    2. Does the program execute all lines in the SETUP_EXTERNAL_XTAL() function? Or does it get stuck somewhere in here?

    3. Can you send me a picture of your XTAL schematic?

    4. I assume this is for a custom PCB you designed. Can you confirm that this is the case? Or is this a TI board (LaunchPad)?

    5. We have code examples showing how to configure external XTALs for the FR2355 device. These can be found by opening CCS and navigating to View > Resource Explorer. In Resource Explorer, navigate to Software > MSP430Ware > Devices > MSP430FR2XX_4XX > MSP430FR2355 > Peripheral Examples > Register Level. Here you will see a bunch of msp430fr235x_CS_xx.c examples. It looks like msp430fr235x_CS_04.c, msp430fr235x_CS_05_.c, and msp430fr235x_CS_10.c show LFXT (32kHz) configurations, but these still might be helpful to check out.

    Thanks!

    -Mitch

  • Hi Nikola,

    I noticed this line:

    //Select XT1 as ACLK source
    //CS_initClockSignal(CS_ACLK,CS_XT1CLK_SELECT,CS_CLOCK_DIVIDER_4);

    Here you are using the 20MHz XTAL as the ACLK source and you are providing a divider setting of 128. This gives an ACLK frequency of 20,000,000/128 = 156.25kHz, which ACLK cannot support. Please see the note from the user's guide below:

    Can you use a bigger divider so that ACLK is less than or equal to 40kHz?

    Another thing to just double check - is the XTS bit set? This bit enables the high frequency mode of XT1.

    Thanks!

    -Mitch

  • Hi Mitch,

    first super big thank you for your time and effort !!

    1. What XTAL are you using? Are you providing the required effective load capacitance with external caps? More details and calculations for this can be found in our app note linked below. You will want to look at section 2.1

    Had a look through it at the beggining.

    2. Does the program execute all lines in the SETUP_EXTERNAL_XTAL() function? Or does it get stuck somewhere in here?

    Yes and then it finishes in NMI.

    3. Can you send me a picture of your XTAL schematic?

    Of course, 

    Design is copied from EXP-MSP430FR2355 and we added 20MHz XTAL (also left pads for 32K if we need to).

    4. I assume this is for a custom PCB you designed. Can you confirm that this is the case? Or is this a TI board (LaunchPad)?

    Yes it is, and general MCU stuff are based on EXP-MSP430FR2355.

    5. We have code examples showing how to configure external XTALs for the FR2355 device. These can be found by opening CCS and navigating to View > Resource Explorer. In Resource Explorer, navigate to Software > MSP430Ware > Devices > MSP430FR2XX_4XX > MSP430FR2355 > Peripheral Examples > Register Level. Here you will see a bunch of msp430fr235x_CS_xx.c examples. It looks like msp430fr235x_CS_04.c, msp430fr235x_CS_05_.c, and msp430fr235x_CS_10.c show LFXT (32kHz) configurations, but these still might be helpful to check out.

    Yes we started from examples MSP430Ware_3_80_07_00\driverlib\examples\MSP430FR2xx_4xx ...

    But no example is given for HF XTALs.

  • Sorry for pasting....

    This was under comment as you see.... forgot to clear it out.

    //Select XT1 as ACLK source
    //CS_initClockSignal(CS_ACLK,CS_XT1CLK_SELECT,CS_CLOCK_DIVIDER_4);

  • Forgot to say that:

    status = CS_clearAllOscFlagsWithTimeout(1000);

    return number 3.

  • Hi Nikola,

    Thanks for the info. The fact that status = CS_clearAllOscFlagsWithTimeout(1000); returns 3 means that the oscillator fault flag is getting set:

    So the problem seems to stem from your XTAL. Can you tell me the part number of the XTAL? I would like to see what the recommended layout is in the documentation and compare it to your schematic.

    Thanks,

    Mitch

  • Hi Nikola,

    The datasheet for the 20MHz XTAL shows a required load capacitance of 8pF. 

    Let's also consider the load capacitor equation example from the app note referenced earlier:

    The parasitic capacitance per pin on the FR2355 device is 2pF. Given all of this info, we should be using load capacitors with a value of:

    (2 x Cload) - Cparasitic = (2 x 8pF) - 2pF = 14pF


    I recommend switching your load caps out with 14pF caps.

    Could you also send me your layout? In case changing the load caps doesn't work, I'd like to see if there are any potential issues with the layout.

    Thanks,

    Mitch

  • Hi,

    we have ditched design and re-doing PCB according to example from:

    http://www.ti.com/lit/ug/slau680/slau680.pdf

    Also issue from the example in the PDF which seems to not fit the equation (datasheet for the 32K XTAL: hr.mouser.com/.../ecx-31b-1108368.pdf)

    Cload - Crystal, 32.768 KHz, 12.5 pF, SMD  - so.. it is 12.5 pF

    and... CL1 = (2 x 12.5) - 2 = 22 pF

    How is possible that this works?

    Our new design is copy paste of this design?  We hope it will work the same... (by magic).

    Going for another board (we also got) .... http://www.ti.com/lit/ug/slau535b/slau535b.pdf

    Again the same....

    Cload = 7pF 

    CL1 = CL2 = 10pF

    So.... (2 x 7) - 2 = 12pF ... the use 10pF... it is close.... but why not exact?

    Kind regards,

    N.

  • Hi Nikola,

    The oscillator circuits we use are technically sub-optimal since we don't use the calculated load cap values. However, our test results show that these circuits give us acceptable results, so we use these cap values across several LaunchPads.

    I recommend you use load cap values calculated from the equation. 

    You are free to use our XTAL circuits for your design, but if you would like to try to avoid a PCB re-design we can keep looking into what you currently have a bit further. Did you try the new 14pF load cap values? 

    Another thing I am concerned about is the actual layout of your current circuit. If you have both the 20MHz and 32kHz crystals on the same traces, the 32kHz pads might be causing an antennae when you are trying to start the 20MHz xtal. If you want me to take a look at your layout, please send it.

    Thanks,

    Mitch

  • Hi Mitch,

    we have decided that first design wasn't good enough in any way so we are going with PCB2.

    On that path we are using reference design from EXP-MSP430FR2355  (launchpad board).

    Hopefully it will work this time :)

    This is the design:

    BR,

    Nikola.

  • Hi Nikola,

    Alright, sounds good! Hopefully I was able to help highlight certain things to consider when designing your XTAL circuit. Good luck with the next layout!

    -Mitch

  • Hi Mitch,

    absolutely you were, thank you for persistence and all the help and effort!

    If anything seems suspicious about presented design please hint before we pull all hair that's left :)

    When we tryout new design I will mark your last answer as resolved so it stays for one who will need it in the future.

    BR,

    Nikola.

  • Absolutely!

    Overall, the XTAL circuit looks good. Just want to point out a very minor difference from the FR2355 layout:

    The traces from the XTAL to the load caps are straight. Your layout should be fine, but if you're going through the effort of re-designing your layout, I wanted to point out this very minor difference. 

    Even though the FR2355 layout shown above is for a 32kHz xtal, these general guidelines apply to both 32kHz and high frequency (20MHz) xtal circuits:

    1. Make sure XTAL traces are straight and are equal in length

    2. The closer you can get the xtal to the MCU, the better.

    Hope this helps!

    -Mitch

  • Hi Mitch,

    big thanks for your feedback!!

    Will report on the outcome.

    BR,

    Nikola.

  • Hi Mitch, 

    just to update info, we have resolved issue by redesign. 

    Added more distance between some of our lines going near the XTAL and generally adding more space around MCU seems to solve the issue.

    BR,

    Nikola.

  • Great! Glad you got it working! Thanks for the update

    -Mitch

**Attention** This is a public forum