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/MSP432P401R: MSP432

Part Number: MSP432P401R

Tool/software: Code Composer Studio

I want to use HFXTL oscillator to generate the 48MHz out of SMCLK that I am going to use for my I2C clock. I am not sure whether the initialisation routine is correct. Can anybody point out any mistake in following routine. Note that I am not using any low power mode:

void clock_setup(){

CS->KEY = CS_KEY_VAL; //Enter the CS key to unlock the registers
CS->CTL1 = CS_CTL1_SELS__HFXTCLK ; //Select HFXTCLK as source for SMCLK
CS->CTL2 = CS_CTL2_HFXT_EN | CS_CTL2_HFXTFREQ_6 ; //Turns on the HFXT oscillator regardless if used as a clock resource, 40 - 48 MHz clock,
while(!(CS->STAT & CS_STAT_SMCLK_READY)) ; //Wait for SMCLK to be stable
}

  • TI provides the driverlib which takes care about most of the initialization functions required for the device setup. Below you can see the HFXT startup function from this library as reference so you can compare.

    In general using the driverlib can make many things easier and save time and development effort. Additional Info can be found here:

    http://dev.ti.com/tirex/#/?link=Software%2FSimpleLink%20MSP432P4%20SDK%2FDocuments%2FDriverLib

    bool CS_startLFXTWithTimeout(uint32_t xtDrive, uint32_t timeout)
    {
        uint8_t bNMIStatus;
        bool boolBypassMode, boolTimeout;
    
        ASSERT(lfxtFreq != 0)
        ASSERT(
                (xtDrive == CS_LFXT_DRIVE0) || (xtDrive == CS_LFXT_DRIVE1)
                || (xtDrive == CS_LFXT_DRIVE2)
                || (xtDrive == CS_LFXT_DRIVE3)
                || (xtDrive == CS_LFXT_BYPASS));
    
        /* Unlocking the CS Module */
        CS->KEY = CS_KEY;
    
        /* Saving status and temporarily disabling NMIs for UCS faults */
    #ifdef __MCU_HAS_SYSCTL_A__
        bNMIStatus = SysCtl_A_getNMISourceStatus() & SYSCTL_A_CS_SRC;
        SysCtl_A_disableNMISource(SYSCTL_A_CS_SRC);
    #else
        bNMIStatus = SysCtl_getNMISourceStatus() & SYSCTL_CS_SRC;
        SysCtl_disableNMISource(SYSCTL_CS_SRC);
    #endif
        boolBypassMode = (xtDrive == CS_LFXT_BYPASS) ? true : false;
        boolTimeout = (timeout == 0) ? false : true;
    
        /* Setting to maximum drive strength  */
        if (boolBypassMode)
        {
            BITBAND_PERI(CS->CTL2, CS_CTL2_LFXTBYPASS_OFS) = 1;
        } else
        {
            CS->CTL2 |= (CS_LFXT_DRIVE3);
            BITBAND_PERI(CS->CTL2, CS_CTL2_LFXTBYPASS_OFS) = 0;
        }
    
        /* Waiting for frequency stabilization */
        BITBAND_PERI(CS->CTL2, CS_CTL2_LFXT_EN_OFS) = 1;
    
        while (BITBAND_PERI(CS->IFG, CS_IFG_LFXTIFG_OFS))
        {
            if (boolTimeout && ((--timeout) == 0))
                break;
    
            BITBAND_PERI(CS->CLRIFG,CS_CLRIFG_CLR_LFXTIFG_OFS) = 1;
        }
    
        /* Setting the drive strength */
        if (!boolBypassMode)
        {
            CS->CTL2 = ((CS->CTL2 & ~CS_LFXT_DRIVE3) | xtDrive);
        }
    
        /* Locking the module */
        BITBAND_PERI(CS->KEY, CS_KEY_KEY_OFS) = 1;
    
        /* Enabling the NMI state */
    #ifdef __MCU_HAS_SYSCTL_A__
        SysCtl_A_enableNMISource(bNMIStatus);
    #else
        SysCtl_enableNMISource(bNMIStatus);
    #endif
    
        if (boolTimeout && timeout == 0)
            return false;
    
        return true;
    }
    

  • One additional note:
    while(!(CS->STAT & CS_STAT_SMCLK_READY)) ; //Wait for SMCLK to be stable
    Should be used to check if the clock has settled after a divider change,
    is not the right method to check if the HF Xtal has started and stabilized.

    Regards,
    Stefan
  • Hi,

    could you get your problem solved? If yes, please select "Resolved" for the post that solved your issue so this thread can be closed out. If you have a different question, please select "Ask a related question" or " Ask a new question".
    Thanks a lot!

    Best regards,
    Stefan

**Attention** This is a public forum