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.
/*EDIT: Future thread reader, the actual cause to this problem was that I was missing this line of code
* PJSEL0 |= BIT4 | BIT5 | BIT6 | BIT7; // For XT1 and XT2
* Which sets the GPIO pins the oscillators are on as crystal inputs rather than just GPIO. I had stopped reading the ports once it got to the letter named ports.
*/
So I'm on the latest CCS, I'm using the standalone MSP430FET programmer rather than the one built into the dev board, and I added my own 12MHz oscillator to Y1. I built my clock initializer out of the msp430ware drivers, specifically CS.c. When I run the code below, I always end up timing out both crystals.
uint8_t init_crystals(){
//This function initializes the High Frequency crystal on X2 and the Low Frequency crystal on X1
//Additionally, it sets and sources each system clock appropriately. (See additional documentation for what that entails)
//Lastly, this function returns a status vector indicating what if any errors have occured
uint8_t crystal_errors = 0;
//-----------------------LF Freq, HF Freq
CS_setExternalClockSource(32768, 12000000); //This tells future functions what frequency the low and high frequency are
if(CS_turnOnHFXTWithTimeout(CS_HFXT_DRIVE_8MHZ_16MHZ, 0xFFF)){
//"STATUS_SUCCESS == 1, STATUS_FAILURE == 0, so this IF procs on the crystal working properly
if(CS_turnOnLFXTWithTimeout(CS_LFXT_DRIVE_3, 0xFFF)){
//"STATUS_SUCCESS == 1, STATUS_FAILURE == 0, so this IF procs on the crystal working properly
//In this state, both crystals activated successfully, so now it's time to set up our clock sources.
FRAMCtl_configureWaitStateControl(FRAMCTL_ACCESS_TIME_CYCLES_1); //Effective Frequency = Nominal * 1/(1+cycles), so we're only using one here.
CS_initClockSignal(CS_MCLK, CS_HFXTCLK_SELECT, CS_CLOCK_DIVIDER_1); //Errata note: never raise SMCLK above MCLK in one step, they must at some point sync
CS_initClockSignal(CS_SMCLK, CS_HFXTCLK_SELECT, CS_CLOCK_DIVIDER_8); //That sets this guy to 1.5 Mhz, for reasons I guess.
CS_initClockSignal(CS_ACLK, CS_LFXTCLK_SELECT, CS_CLOCK_DIVIDER_1);
} else{
//"STATUS_SUCCESS == 1, STATUS_FAILURE == 0, so this ELSE procs on the crystal failing to initialize
//In this state, the 12MHz crystal activated successfully but the 32.768 KHz did not.
//We should first put everything on the working crystal
//Then we need to set the DCO to emulate the 32.768 KHz, but it doesn't actually do that so LF Modclock?
//And use it to source the relevant clocks
FRAMCtl_configureWaitStateControl(FRAMCTL_ACCESS_TIME_CYCLES_1); //Effective Frequency = Nominal * 1/(1+cycles), so we're only using one here. CS_initClockSignal(CS_MCLK, CS_HFXTCLK_SELECT, CS_CLOCK_DIVIDER_1); //Errata note: never raise SMCLK above MCLK in one step, they must at some point sync
CS_initClockSignal(CS_SMCLK, CS_HFXTCLK_SELECT, CS_CLOCK_DIVIDER_8); //That sets this guy to 1.5 Mhz, for reasons I guess.
CS_initClockSignal(CS_ACLK, CS_LFMODOSC_SELECT, CS_CLOCK_DIVIDER_1);
crystal_errors |= 0x0A;
}
} else{
//"STATUS_SUCCESS == 1, STATUS_FAILURE == 0, so this ELSE procs on the crystal failing to initialize
crystal_errors |= 0x50;
if(CS_turnOnLFXTWithTimeout(CS_LFXT_DRIVE_3, 0xFFF)){
//"STATUS_SUCCESS == 1, STATUS_FAILURE == 0, so this IF procs on the crystal working properly
//In this state, the 32.768 KHz crystal activated successfully but the 12MHz did not
//This device lacks a FLL, so we can't use the 32Khz to do improve upon the internal oscillators
//So, we first need to set the DCO to 12Mhz, then we set up our clock sources
//To do that we first set the DCO to 24Mhz, then divide by half when going into our MCLK
//---------High frequency mode, max frequency
CS_setDCOFreq(CS_DCORSEL_1, CS_DCOFSEL_6);
FRAMCtl_configureWaitStateControl(FRAMCTL_ACCESS_TIME_CYCLES_1); //Effective Frequency = Nominal * 1/(1+cycles), so we're only using one here.
CS_initClockSignal(CS_MCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_2); //Errata note: never raise SMCLK above MCLK in one step, they must at some point sync
CS_initClockSignal(CS_SMCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_16); //That sets this guy to 1.5 Mhz, for reasons I guess.
CS_initClockSignal(CS_ACLK, CS_LFXTCLK_SELECT, CS_CLOCK_DIVIDER_1);
} else{
//"STATUS_SUCCESS == 1, STATUS_FAILURE == 0, so this ELSE procs on the crystal failing to initialize
//In this state, both clocks failed. This is VERY bad, but we'll do our best.
//So, we first need to set the DCO to 12Mhz, then we set up our clock sources
//To do that we first set the DCO to 24Mhz, then divide by half when going into our MCLK
//---------High frequency mode, max frequency
CS_setDCOFreq(CS_DCORSEL_1, CS_DCOFSEL_6);
FRAMCtl_configureWaitStateControl(FRAMCTL_ACCESS_TIME_CYCLES_1); //Effective Frequency = Nominal * 1/(1+cycles), so we're only using one here.
CS_initClockSignal(CS_MCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_2); //Errata note: never raise SMCLK above MCLK in one step, they must at some point sync
CS_initClockSignal(CS_SMCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_16); //That sets this guy to 1.5 Mhz, for reasons I guess.
CS_initClockSignal(CS_ACLK, CS_LFMODOSC_SELECT, CS_CLOCK_DIVIDER_1);
crystal_errors |= 0x0A;
}
}
return crystal_errors;
}
I've also tried running without those timers and seeing if it'll stabilize with the following code, also to no effect.
void crystal_hard_loop(uint8_t crystal_errors){
if(crystal_errors & 0x0A){
CS_turnOnLFXT(CS_LFXT_DRIVE_3);
crystal_errors &= ~0x0A;
}
if(crystal_errors & 0x50){
CS_turnOnHFXT(CS_HFXT_DRIVE_8MHZ_16MHZ);
crystal_errors &= ~0x50;
}
}
and in my main loop it's just running as follows
int main(void)
{
WDTCTL = WDTPW | WDTHOLD; // stop watchdog timer
PM5CTL0 &= ~LOCKLPM5; // Disable the GPIO power-on default high-impedance mode
//Enable Interrupts
__enable_interrupt();
//Initialize global variables
uint8_t crystal_errors;
crystal_errors = init_crystals();
__no_operation();
//crystal_hard_loop(crystal_errors);
while(crystal_errors == 0x50);
while(crystal_errors == 0x0A);
while(crystal_errors == 0x5A);
while(crystal_errors == 0);
while(1);
return 0;
}
I'm at a bit of a loss because I'm largely only using Ti provided clock system code, on the Ti designed board. Trying to make sure I get this right now on that dev board so when I use this chip on other boards I can properly diagnose if it's a hardware issue there.
Hi Andy,
You might find this post useful as it covers a lot of relevant information regarding getting your crystal to work:
Please note that you will need an extra FRAM wait state when operating at frequencies above 8MHz. Have you tried the example in resource explorer for the 32kHz crystal?
BR,
Leo
Well, I completely misread that example code when I was skimming earlier, and missed that while it sources MCLK off the DCO it still sets up the other oscillators. Plugged it in and everything ran just fine, both clocks are working. I only got to scope the LFXT because the 2.0 pin isn't exposed on the dev board anywhere I could find it, but the flags cleared and that should mean it's fine. I'm not sure what's different between the two code sets, and I'll need to look into that more later just to know what's going on, but this definitely resolves my issue, thanks!
**Attention** This is a public forum