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.

[参考译文] MSP430F5529:无法将时钟源更改为 XT2

Guru**** 2386950 points
请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/msp-low-power-microcontrollers-group/msp430/f/msp-low-power-microcontroller-forum/1441653/msp430f5529-unable-to-change-clock-source-to-xt2

器件型号:MSP430F5529

工具与软件:

我使用的是 MSP430F5529LP 开发板。 默认情况下、它在1MHz 上运行。 开发板还附带一个4MHz 晶体、该晶体可用作 XT2处的时钟源。 我正在尝试这么做、但出于某种原因、代码会卡在 while 循环中、因为 XT1LFOFFG 标志永远不会被清除。 以下是我的参考代码:

void initClocks(void) 
{
    // Step 1: Configure XT2 pins
    P5SEL |= BIT2 | BIT3;      // Select XT2 function on P5.2 and P5.3
    // Step 1: Disable XT1
       UCSCTL6 |= XT1OFF;         // Explicitly turn off XT1

       // Step 2: Set ACLK to use REFO
       UCSCTL4 = (UCSCTL4 & ~SELA_7) | SELA__REFOCLK; // Use REFO for ACLK

       // Step 3: Configure XT2 for MCLK and SMCLK
       P5SEL |= BIT2 | BIT3;      // Enable XT2 function on P5.2 and P5.3
       UCSCTL6 &= ~XT2OFF;        // Enable XT2 oscillator

       // Step 4: Wait for XT2 to stabilize
       do {
           UCSCTL7 &= ~(XT1LFOFFG | XT2OFFG); // Clear XT1 and XT2 fault flags
           SFRIFG1 &= ~OFIFG;                 // Clear global oscillator fault flag
           __delay_cycles(5000);              // Delay for stabilization
       } while (SFRIFG1 & OFIFG);             // Wait until faults are cleared

       // Step 5: Set MCLK and SMCLK to use XT2
       UCSCTL4 = (UCSCTL4 & ~(SELM_7 | SELS_7)) | SELM__XT2CLK | SELS__XT2CLK;

       // Step 6: Set dividers (optional)
       UCSCTL5 &= ~(DIVM_7 | DIVS_7); // Clear dividers
       UCSCTL5 |= DIVM__1 | DIVS__1;  // No division for MCLK and SMCLK
}

它会卡在第4步中。

问题可能是什么? 我将在停止看门狗后立即调用此函数。  

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好!

    XT1LFOFFG 表明低频 XT1 (32 768Hz 晶振)存在问题。 您不会在您的代码中配置该晶体。 因此、当您检查此故障标志时、将会报告问题。 您还需要在代码中配置 XT1。  

    此致、

    Cash Hao

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好!  

    感谢您的响应。  

    我已经编写了关闭 XT1的代码。 我还需要做更多吗?

           UCSCTL6 |= XT1OFF;         // Explicitly turn off XT1
    
           // Step 2: Set ACLK to use REFO
           UCSCTL4 = (UCSCTL4 & ~SELA_7) | SELA__REFOCLK; // Use REFO for ACLK

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好!

    因为您不使用 XT1。 您可以 在代码中忽略 XT1LFOFFG 标志。 无需在第20行进行检查。

    此致、

    Cash Hao