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.

430F6723的RTC不能使用内部时钟REFOCLK吗?

Other Parts Discussed in Thread: MSP430F5438A, MSP430F6723

在430F6723的时钟配置如下:

UCSCTL4 &= ~(SELA0 | SELA1 | SELA2); // Ensure XT1 is ACLK source // (127+1) x 32768 = 4194304hz(4.19455)
UCSCTL4 |= SELA1;
UCSCTL3 |= SELREF__REFOCLK;
do
{
UCSCTL7 &= ~(XT2OFFG | XT1LFOFFG | DCOFFG);
// Clear XT2,XT1,DCO fault flags
SFRIFG1 &= ~OFIFG; // Clear fault flags
} while ((SFRIFG1 & OFIFG)&&(delay--)); // Test oscillator fault flag

///jackwei时钟SMCLK变为4194304hz
__bis_SR_register(SCG0); // 禁止FLL功能
UCSCTL0 = 0x0000 ;
UCSCTL1 = DCORSEL_5; // DCO频率为(2.5~6MHz)手册37页
UCSCTL2 = FLLD_1 + 127; // 设置DCO频率为4194304hz
__bic_SR_register(SCG0); // 使能FLL功能

设置的ACLK为REFOCLK时钟源

在RTC的配置为:

void rtc_init(void)
{
// RTCCTL1 = RTCTEVIE + RTCRDYIE + RTCMODE+ RTCSSEL_0+ RTCTEV__MIN+ RTCAIE; //
RTCCTL0_H = RTCKEY_H; //解锁RTC_C模块
RTCCTL0_L = RTCTEVIE+ RTCRDYIE + RTCAIE ; //启用RTC时间事件中断
RTCCTL13 = RTCTEV_3+ RTCMODE + RTCHOLD+ RTCSSEL_0; // BCD模式,RTC保持,将RTCTEV设置为12:00分钟警报,32khz RTCBCD++ RTCHOLD
//事件中断
RTCYEAR = 2020; // Year = 0x2020
RTCMON = 8; //月= 0x10 =十月
RTCDAY = 3; // Day = 0x07 = 7th
RTCDOW = 1; //星期几= 0x05 =星期五
RTCHOUR = 5; //小时= 0x11
RTCMIN = 59; //分钟=59
RTCSEC = 0; //秒= 0


RTCCTL13 &=~(RTCHOLD); //启动RTC日历模式
RTCCTL0_H = 0; //锁定RTC_C模块
RTCAHOUR = RTCAE + 6;
}

不知为什么RTC 的中断很长时间才进入一次。大约50s进入RTCIV_RTCRDYIFG中断1次。

其中 中断源中RTCOFIFG =1;

TIMEARA中配置的时间较为准确,不知道什么原因导致RTC差距很大。

  • 参考用户指南 21.1 RTC Overview

    https://www.ti.com.cn/cn/lit/ug/slau208q/slau208q.pdf

    综上,可以使用的·

  • 那这个和我配置的什么有关系呢??RTC中断进不去
  • 请给出完整程序,我来测试一下,谢谢
  • 我这边使用MSP430F5438A测试了一下是可以进入中断的,代码和测试结果如下

    /* --COPYRIGHT--,BSD_EX
     * Copyright (c) 2012, Texas Instruments Incorporated
     * All rights reserved.
     *
     * Redistribution and use in source and binary forms, with or without
     * modification, are permitted provided that the following conditions
     * are met:
     *
     * *  Redistributions of source code must retain the above copyright
     *    notice, this list of conditions and the following disclaimer.
     *
     * *  Redistributions in binary form must reproduce the above copyright
     *    notice, this list of conditions and the following disclaimer in the
     *    documentation and/or other materials provided with the distribution.
     *
     * *  Neither the name of Texas Instruments Incorporated nor the names of
     *    its contributors may be used to endorse or promote products derived
     *    from this software without specific prior written permission.
     *
     * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
     * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
     * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
     * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
     * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     *
     *******************************************************************************
     *
     *                       MSP430 CODE EXAMPLE DISCLAIMER
     *
     * MSP430 code examples are self-contained low-level programs that typically
     * demonstrate a single peripheral function or device feature in a highly
     * concise manner. For this the code may rely on the device's power-on default
     * register values and settings such as the clock configuration and care must
     * be taken when combining code from several examples to avoid potential side
     * effects. Also see www.ti.com/grace for a GUI- and www.ti.com/msp430ware
     * for an API functional library-approach to peripheral configuration.
     *
     * --/COPYRIGHT--*/
    //******************************************************************************
    //  MSP430F543xA Demo - RTC in Counter Mode toggles P1.0 every 1s
    //
    //  This program demonstrates RTC in counter mode configured to source from ACLK
    //  to toggle P1.0 LED every 1s.
    //
    //                MSP430F5438A
    //             -----------------
    //        /|\ |                 |
    //         |  |                 |
    //         ---|RST              |
    //            |                 |
    //            |             P1.0|-->LED
    //
    //   M. Morales
    //   Texas Instruments Inc.
    //   June 2009
    //   Built with CCE Version: 3.2.2 and IAR Embedded Workbench Version: 4.11B
    //******************************************************************************
    
    #include <msp430.h>
    
    int main(void)
    {
      WDTCTL = WDTPW+WDTHOLD;
    
      UCSCTL4 = SELM__REFOCLK + SELS__REFOCLK + SELA__REFOCLK;       // MCLK = SMCLK = ACLK = REFOCLK
    
      P1OUT |= 0x01;
      P1DIR |= 0x01;
    
      // Setup RTC Timer
      RTCCTL01 = RTCTEVIE + RTCSSEL_0 + RTCTEV_0; // Counter Mode, RTC1PS, 8-bit ovf
                                                // overflow interrupt enable
      RTCPS0CTL = RT0PSDIV_2;                   // ACLK, /8, start timer
      RTCPS1CTL = RT1SSEL_2 + RT1PSDIV_3;       // out from RT0PS, /16, start timer
    
      __bis_SR_register(LPM3_bits + GIE);
    }
    
    #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
    #pragma vector=RTC_VECTOR
    __interrupt void RTC_ISR(void)
    #elif defined(__GNUC__)
    void __attribute__ ((interrupt(RTC_VECTOR))) RTC_ISR (void)
    #else
    #error Compiler not supported!
    #endif
    {
      switch(__even_in_range(RTCIV,16))
      {
        case 0: break;                          // No interrupts
        case 2: break;                          // RTCRDYIFG
        case 4:                                 // RTCEVIFG
          P1OUT ^= 0x01;
          break;
        case 6: break;                          // RTCAIFG
        case 8: break;                          // RT0PSIFG
        case 10: break;                         // RT1PSIFG
        case 12: break;                         // Reserved
        case 14: break;                         // Reserved
        case 16: break;                         // Reserved
        default: break;
      }
    }
    

  • int main(void)//
    {
        WDTCTL = WDTPW | WDTHOLD;               // Stop WTD
    
        // Initialize LFXT1
    //    UCSCTL6 &= ~(XT1OFF);                   // Enable XT1
    //    UCSCTL6 |= XCAP_3;                      // Internal load cap
    //
    //    // Loop until XT1, XT2 & DCO fault flag is cleared
    //    do
    //    {
    //        UCSCTL7 &= ~(XT2OFFG | XT1LFOFFG | DCOFFG);
    //        // Clear XT2,XT1,DCO fault flags
    //        SFRIFG1 &= ~OFIFG;                  // Clear fault flags
    //    } while (SFRIFG1 & OFIFG);              // Test oscillator fault flag
        
        UCSCTL4 = SELM__REFOCLK + SELS__REFOCLK + SELA__REFOCLK; 
        UCSCTL3 |= SELREF__REFOCLK;
    //    _bis_SR_register(SCG0);                    // 禁止FLL功能
    //    UCSCTL0 = 0x0000 ;
    //    UCSCTL1 = DCORSEL_5;                      // DCO频率为(2.5~6MHz)手册37页
    //    UCSCTL2 = FLLD_1 + 127;                   // 设置DCO频率为4194304hz
    //    __bic_SR_register(SCG0);                    // 使能FLL功能
        
        P1OUT &= ~BIT0;                         // Clear P1.0 output
        P1DIR |= BIT0;                          // Set P1.0 as output
        P1OUT &= ~BIT1;                         // Clear P1.0 output
        P1DIR |= BIT1;                          // Set P1.0 as output
    
        // Configure RTC_C
        RTCCTL0_H = RTCKEY_H;                   // Unlock RTC_C module
        RTCCTL0_L |= RTCTEVIE | RTCMODE|RTCAIE | RTCRDYIE; // Enable RTC time event, alarm event,
                                                // read ready interrupt
        RTCCTL1 |= RTCBCD | RTCHOLD;            // RTC enable BCD mode, RTC hold
    
        RTCYEAR = 0x2011;                       // Year = 0x2011 = 2011
        RTCMON = 0x12;                          // Month = 0x12 = December
        RTCDAY = 0x05;                          // Day = 0x05 = 5th
        RTCDOW = 0x03;                          // Day of week = 0x03 = Wednesday
        RTCHOUR = 0x24;                         // Hour = 0x12
        RTCMIN = 0x59;                          // Minute = 0x57
        RTCSEC = 0x55;                          // Seconds = 0x36
    
        RTCADOWDAY = 0x3;                       // RTC Day of week alarm = 0x2
        RTCADAY = 0x22;                         // RTC Day Alarm = 0x22
        RTCAHOUR = 0x23;                        // RTC Hour Alarm
        RTCAMIN = 0x45;                         // RTC Minute Alarm
    
        RTCCTL1 &= ~(RTCHOLD);                  // Start RTC calendar mode
        RTCCTL0_H = 0;                          // Lock RTC_C module
    
        __bis_SR_register(GIE);     // Enter LPM3 w/ interrupts enabled
        while(1)
        {
           P1OUT ^= BIT1;  
           __delay_cycles(0x3600);
        }
        //__no_operation();
    }
    
    // RTC Interrupt Service Routine
    #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
    #pragma vector=RTC_VECTOR
    __interrupt void rtc_isr(void)
    #elif defined(__GNUC__)
    void __attribute__ ((interrupt(RTC_VECTOR))) rtc_isr (void)
    #else
    #error Compiler not supported!
    #endif
    {
        switch (__even_in_range(RTCIV, 16))
        {
            case RTCIV_NONE:                    // No interrupts
                break;
            case RTCIV_RTCOFIFG:                // RTCOFIFG
                break;
            case RTCIV_RTCRDYIFG:               // RTCRDYIFG
                P1OUT ^= 0x01;                  // Toggles P1.0 every second
                break;
            case RTCIV_RTCTEVIFG:               // RTCEVIFG
                __no_operation();               // Interrupts every minute
                break;
            case RTCIV_RTCAIFG:                 // RTCAIFG
                __no_operation();               // Interrupts every alarm event
                break;
            case RTCIV_RT0PSIFG:                // RT0PSIFG
                break;
            case RTCIV_RT1PSIFG:                // RT1PSIFG
                break;
            case 14: break;                     // Reserved
            case 16: break;                     // Reserved
            default: break;
        }
    }

    你使用的是RTC的计数器模式,而不是日历的模式。你在日历模式试一下,我这边是很久才会进入一次中断,谢谢

  • 好的,我会在下午测试后给您回复
  • user791567 说:
    我这边是很久才会进入一次中断

    能否详细描述一下?

    我这边用下面的代码测试了一下,运行正常,P1.0每秒闪烁一下,而后会进入RTCEVIFG

    
    #include <msp430.h>
    
    int main(void)
    {
      WDTCTL = WDTPW + WDTHOLD;                 // Stop Watchdog Timer
      P1DIR |= BIT0;                            // Set P1.0 as output
    
      UCSCTL4 = SELM__REFOCLK + SELS__REFOCLK + SELA__REFOCLK;       // MCLK = SMCLK = ACLK = REFOCLK
    
      // Configure RTC_A
      RTCCTL01 |= RTCTEVIE + RTCRDYIE + RTCBCD + RTCHOLD + RTCMODE;
                                                // RTC enable, BCD mode, RTC hold
                                                // enable RTC read ready interrupt
                                                // enable RTC time event interrupt
    
      RTCYEAR = 0x2010;                         // Year = 0x2010
      RTCMON = 0x4;                             // Month = 0x04 = April
      RTCDAY = 0x05;                            // Day = 0x05 = 5th
      RTCDOW = 0x01;                            // Day of week = 0x01 = Monday
      RTCHOUR = 0x10;                           // Hour = 0x10
      RTCMIN = 0x32;                            // Minute = 0x32
      RTCSEC = 0x45;                            // Seconds = 0x45
    
      RTCADOWDAY = 0x2;                         // RTC Day of week alarm = 0x2
      RTCADAY = 0x20;                           // RTC Day Alarm = 0x20
      RTCAHOUR = 0x10;                          // RTC Hour Alarm
      RTCAMIN = 0x23;                           // RTC Minute Alarm
    
      RTCCTL01 &= ~(RTCHOLD);                   // Start RTC calendar mode
    
      __bis_SR_register(LPM3_bits + GIE);       // Enter LPM3 mode with interrupts
                                                // enabled
      __no_operation();
    }
    
    #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
    #pragma vector=RTC_VECTOR
    __interrupt void RTC_ISR(void)
    #elif defined(__GNUC__)
    void __attribute__ ((interrupt(RTC_VECTOR))) RTC_ISR (void)
    #else
    #error Compiler not supported!
    #endif
    {
      switch(__even_in_range(RTCIV,16))
      {
        case RTC_NONE:                          // No interrupts
          break;
        case RTC_RTCRDYIFG:                     // RTCRDYIFG
          P1OUT ^= 0x01;                        // Toggles P1.0 every second
          break;
        case RTC_RTCTEVIFG:                     // RTCEVIFG
          __no_operation();                     // Interrupts every minute
          break;
        case RTC_RTCAIFG:                       // RTCAIFG
          break;
        case RTC_RT0PSIFG:                      // RT0PSIFG
          break;
        case RTC_RT1PSIFG:                      // RT1PSIFG
          break;
        case 12: break;                         // Reserved
        case 14: break;                         // Reserved
        case 16: break;                         // Reserved
        default: break;
      }
    }
    
    
    

  • 我焊接XT1的晶振(32.768KHZ)的话也是会进入中断,如果去掉晶振RTC的中断就不进入了。使用的是MSP430F6723,使用上面的程序
  • 能否去掉外部晶振进行测量呢?
  • 我这边没有MSP430F6723的板子只有MSP430F5438A的板子,板子上已经固定了XT1,我回头找找其他板子来测试一下
  • 您现在使用的是RTC_C,查看用户指南可知:

    1.2.2 Real-Time Clock and Prescale Dividers 

    The low-frequency oscillator must be operated at 32768 Hz (nominal) for proper RTC_C operation. RT0PS is sourced from the low-frequency oscillator XT1.

    RTC模块需要使用外部低频振荡器。它必须在32768 Hz下运行。

  • 你好,有没有进行测试呢??这个到底是什么原因造成的呢?
  • user791567 说:
    我焊接XT1的晶振(32.768KHZ)的话也是会进入中断,如果去掉晶振RTC的中断就不进入了。使用的是MSP430F6723,使用上面的程序

     如之前所说,RTC_C的话,需要连接外部晶振XT1