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.

CCS/MSP430FG6626: XTAL1 Clock Issue

Part Number: MSP430FG6626

Tool/software: Code Composer Studio

Using the MSP430FG6626 with two crystals, I am having issues starting XT1CLK which is preventing me from using the RTC_B.

XT2CLK initialized correctly and driving MCLK and SMCLK at 16 MHz and 8 MHz respectively.

Although I don't plan to use ACLK and FLL, I had them configured to be driven by REFOCLK.

Clock Setup

	static WORD16 debug;
	static WORD32 smclkVal;
	static WORD32 mclkVal;
	static WORD32 aclkVal;
	//
	// Initialize
	//
	debug = 0;
	//
	// Port Select XT2
	//
	GPIO_setAsPeripheralModuleFunctionInputPin (GPIO_PORT_P7, PERIPH_IN_PORT7);
	GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P7, PERIPH_OUT_PORT7);
	//
	// Set VCore to 2 for 16MHz clock
	//
	PMM_setVCore(PMM_CORE_LEVEL_1);
	PMM_setVCore(PMM_CORE_LEVEL_2);
	//
	// Initialize Source Crystal Frequencies: XT1 and XT2
	//
	UCS_setExternalClockSource(32768, 16000000);
	//
	// Initialize ACLK and Reference Clock (Won't be Used)
	//
	UCS_initClockSignal(UCS_ACLK, UCS_REFOCLK_SELECT, UCS_CLOCK_DIVIDER_1);
	UCS_initClockSignal(UCS_FLLREF, UCS_REFOCLK_SELECT, UCS_CLOCK_DIVIDER_1);
	//
	// Clock Fault Initialization
	//
	UCS_clearFaultFlag(UCS_XT1LFOFFG | UCS_XT1HFOFFG | UCS_XT2OFFG);
	//
	// Turn On XT1
	//
	if(!UCS_turnOnLFXT1WithTimeout(UCS_XT1_DRIVE_3, UCS_XCAP_3, XT1_INIT_TIMEOUT))
	{
	 	// ***********************
	 	// ***********************
	 	// ***********************
	 	// ***********************
	 	// Timeout Always Occur
	 	// ***********************
	 	// ***********************
	 	// ***********************
	 	// ***********************
	 	// Handle Error Case
		debug++;
	}
	//
	// Initialize XT2 (8MHz to 16MHz operation range)
	//
	if(!UCS_turnOnXT2WithTimeout(UCS_XT2_DRIVE_8MHZ_16MHZ, XT2_INIT_TIMEOUT))
	{
		// Handle Error Case
		debug++;
	}
	//
	// Configure MCLK and SMCLK to XT2 Source
	// - Powers MCU Clock and Peripheral Clocks
	//
   	UCS_initClockSignal(UCS_MCLK,  UCS_XT2CLK_SELECT, UCS_CLOCK_DIVIDER_1);
   	UCS_initClockSignal(UCS_SMCLK, UCS_XT2CLK_SELECT, UCS_CLOCK_DIVIDER_2);
   	//
   	// Enable Global Oscillator Fault Flag
   	//
	SFR_disableInterrupt(SFR_OSCILLATOR_FAULT_INTERRUPT);
	SFR_clearInterrupt  (SFR_OSCILLATOR_FAULT_INTERRUPT);
	//TODO: NMI Clock-Error Free
	//SFR_enableInterrupt (SFR_OSCILLATOR_FAULT_INTERRUPT);
	//
	// Verify Output Frequencies
	//
	smclkVal = UCS_getSMCLK();
	mclkVal  = UCS_getMCLK();
	aclkVal  = UCS_getACLK();
	//
	// Error Case(s)
	//
	if(smclkVal != (XT2_FREQ >> 1))
	{
		debug++;
	}
	if(mclkVal != XT2_FREQ)
	{
		debug++;
	}
	if(aclkVal != 32768)
	{
		debug++;
	}

UCS_turnOnLFXT1WithTimeout() appears to always time out, as timeout value of 50,000 (and likely higher) will not work.
Using UCS_turnOnLFXT1() instead will result in an infinite loop (won't exit function call). Trying different DRIVE_X and CAP_X settings led to the same result.

I'd appreciate any help on this issue.

  • Almost forgot to mentions a couple thing:
    - Oscillator Faults being triggered are XT1LFOFFG and DCOFFG.
    - External Capacitors (12 pF) are being used with external 32768 Hz XTAL1 Oscillator
  • Following up again:

    - No capacitor (Cbak) connected to VBAK pin.
    - Calling BattBak_unlockBackupSubSystem() prior to clock initialization allowed XTAL1 initializations to complete without timeout.
    - Oscillator Fault is now reduced to DCOFFG.

    RTC_B does not run or interrupt after init.

    RTC_B Init

    	Calendar InitTime;
    	//
    	// Setup Time Parameters
    	//
    	InitTime.Seconds	= 0x00;
    	InitTime.Minutes	= 0x00;
    	InitTime.Hours		= 0x11;
    	InitTime.DayOfWeek	= 0;
    	InitTime.DayOfMonth	= 0x11;
    	InitTime.Month		= 0x11;
    	InitTime.Year		= 0x2010;
       	//
      	// Initialize RTS
    	// - Calendar Mode
    	// - Pass-in Init Time (above)
    	// - BCD Register Format
    	//
    	RTC_B_initCalendar(RTC_B_BASE, &InitTime, RTC_B_FORMAT_BCD);
    	//
    	// Setup Calendar Event
    	// - Every Minute
    	//
    	RTC_B_setCalendarEvent(RTC_B_BASE, RTC_B_CALENDAREVENT_MINUTECHANGE);
    	//
    	// Setup Interrupt
    
    	//
    	RTC_B_disableInterrupt(RTC_B_BASE, RTCRDYIFG | RTCTEVIFG | RTCAIFG);
    	RTC_B_clearInterrupt  (RTC_B_BASE, RTCRDYIFG | RTCTEVIFG | RTCAIFG);
    	RTC_B_enableInterrupt(RTC_B_BASE, (RTCRDYIFG | RTCTEVIFG));
      	RTC_B_startClock(RTC_B_BASE);

  • Hi,

    Yes BattBak_unlockBackupSubSystem() needs to be called and that looks like that is the only issue with your code in your original post.

    As for the RTC_B how are you checking if there are no interrupts? Are you setting a breakpoint in the ISR? Also, could you post the ISR so we can see if there is an issue there?

    Regards,
    Nathan
  • Calling BattBak_unlockBackupSubSystem() before XT1CLK initialization was somewhat a curveball because most of the MSP430 driver library code examples does not contain that step ... until I started working on the RTC_B.

    I was able to fix the RTC_B issue. Primarily, I was using the incorrect symbols for enabling/disabling the RTC_B interrupt ... usually the IE and IFG flags are the same for other peripherals. Other things that I needed to do was also call BattBak_unlockBackupSubSystem() at start of RTC Interrupt handler as well (after reading SLAA665B).

    RTC_B Interrupt Setup

    	RTC_B_disableInterrupt(RTC_B_BASE, RTCRDYIE | RTCTEVIE | RTCAIE);
    	RTC_B_clearInterrupt  (RTC_B_BASE, RTCRDYIFG | RTCTEVIFG | RTCAIFG);
    	RTC_B_enableInterrupt(RTC_B_BASE, (RTCTEVIE | RTCRDYIE));
    	RTC_B_startClock(RTC_B_BASE);
    

    RTC_B IRQ

    	//
    	// Unlock Battery Backup
    	//
    	do
    	{
    		Status = BattBak_unlockBackupSubSystem(BAK_BATT_BASE);
    	}
    	while(Status);
    	//
    	// Process Interrupt Vectors
    	//
    	switch(__even_in_range(RTCIV, 16))
    	{
    		..............
    	}
    

    Thanks!

**Attention** This is a public forum