Tool/software: Code Composer Studio
Hello TI community,
I have a serious problem with a 20 MHz crystal which I soldered on the XT1 pads of the MSP-TS430PZ100USB evaluation board.
I have a second HF crystal with 4 MHz soldered on XT2.
The 4Mhz crystal works fine, the 20MHz crystal does not work. I have added 2 capacitors of 22pF according to the formula C1=C2=(2*Cload)-Cparasitic=(2*12pF)-2pF
I have sourced the ACLK with XT2 and routed to P1.0: I can measure a nice 4Mhz squrewave there.
I have sourced the SMCLK with XT1 and routed to P3.4: I can see a DC voltage with some random oscillations (very small) on the pin as soon as I run my code.
Another problem is my MCLK: when I want to modify the SELM bits of the UCSCTL4 register manually, the programm crashes. Also when I use library functions and TI example codes, these problems remain.
Please help me, I am busy since a week with the same issue and I am running out of time.
Here is the code:
#include "driverlib.h"
//*****************************************************************************
//
//Target frequency for MCLK in kHz
//
//*****************************************************************************
#define UCS_DESIRED_MCLK_FREQUENCY_IN_KHZ 20000
//*****************************************************************************
//
//MCLK/FLLRef Ratio (desired frequency / FLL reference clock frequency)
//
//*****************************************************************************
#define UCS_MCLK_FLLREF_RATIO 609
//*****************************************************************************´
//*****************************************************************************
//
//XT Crystal Frequencies being used
//
//*****************************************************************************
#define UCS_XT1_CRYSTAL_FREQUENCY 20000000
#define UCS_XT2_CRYSTAL_FREQUENCY 4000000
//Variable to store current Clock values
uint32_t clockValue = 0;
//Variable to store status of Oscillator fault flags
uint16_t status;
//Variable to store returned STATUS_SUCCESS or STATUS_FAIL
uint8_t returnValue = 0;
void set_clock_frequencies()
{
// SMCLK on Port 3.4 (Pin#46)
GPIO_setAsPeripheralModuleFunctionOutputPin(
GPIO_PORT_P3,
GPIO_PIN4
);
// ACLK on P1.0 (Pin#34)
GPIO_setAsPeripheralModuleFunctionOutputPin(
GPIO_PORT_P1,
GPIO_PIN0
);
//Startup HF XT2 crystal Port select XT2
GPIO_setAsPeripheralModuleFunctionInputPin(
GPIO_PORT_P7,
GPIO_PIN2 + GPIO_PIN3
);
// Set VCore = 3 for 20MHz clock
PMM_setVCore(PMM_CORE_LEVEL_3);
//Set DCO; FLL reference = REFO
UCS_initClockSignal(
UCS_FLLREF,
UCS_REFOCLK_SELECT,
UCS_CLOCK_DIVIDER_1
);
//Set Ratio and Desired MCLK Frequency and initialize DCO
UCS_initFLLSettle(
UCS_DESIRED_MCLK_FREQUENCY_IN_KHZ,
UCS_MCLK_FLLREF_RATIO
);
status = UCS_turnOnHFXT1WithTimeout(UCS_XT1_DRIVE_2, 5000);
status = UCS_turnOnXT2WithTimeout(UCS_XT2_DRIVE_4MHZ_8MHZ, 5000);
#if 0
// Set MCLK with library function
UCS_initClockSignal( // INSIDE THE FUNTION, PROGRAM CRASHES
UCS_MCLK,
UCS_DCOCLK_SELECT,
UCS_CLOCK_DIVIDER_1
);
#endif
#if 0
// Set MCLK manually --> problem remains
// Clear Register
UCSCTL4 &= ~(SELM_7);
// Set XT1 CLK as MCLK source
UCSCTL4 |= SELM__XT1CLK; // HERE PROGRAM CRASHES
// MCLK Source Divider f(MCLK)/1
UCSCTL5 |= DIVM_0;
// Breakpoint here
status = status;
#endif
//Set SMCLK
UCS_initClockSignal(
UCS_SMCLK,
UCS_XT1CLK_SELECT,
UCS_CLOCK_DIVIDER_1
);
//Set ACLK
UCS_initClockSignal(
UCS_ACLK,
UCS_XT2CLK_SELECT,
UCS_CLOCK_DIVIDER_1
);
// Enable global oscillator fault flag
SFR_clearInterrupt(SFR_OSCILLATOR_FAULT_INTERRUPT);
SFR_enableInterrupt(SFR_OSCILLATOR_FAULT_INTERRUPT);
// Enable global interrupt
__bis_SR_register(GIE);
// Verify if the Clock settings are as expected
UCS_setExternalClockSource(UCS_XT1_CRYSTAL_FREQUENCY, UCS_XT2_CRYSTAL_FREQUENCY);
clockValue = UCS_getSMCLK();
clockValue = UCS_getMCLK();
clockValue = UCS_getACLK();
}
#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)
{
do
{
// If it still can't clear the oscillator fault flags after the timeout,
// trap and wait here.
status = UCS_clearAllOscFlagsWithTimeout(1000);
}
while(status != 0);
}
void NMI_ISR(void)
{
do
{
// If it still can't clear the oscillator fault flags after the timeout,
// trap and wait here.
status = UCS_clearAllOscFlagsWithTimeout(1000);
}
while(status != 0);
}
PS:
When I commented The MCLK modification, as you can see in the code, the program does not crash.
And if I apply the DCO clock to SMCLK (Pin 3.4), I can measure 20MHz. Problem: too much jitter, thatswhy I badly need to use a 20MHz crystal at XT1.
Thx for your help in advance,
with kind regards,
Stefan