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.

[参考译文] 创建一小时的延迟

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

https://e2e.ti.com/support/microcontrollers/msp-low-power-microcontrollers-group/msp430/f/msp-low-power-microcontroller-forum/1356848/creation-of-a-delay-of-one-hour

器件型号:MSP430FR2155

您好、TI 专家!

我正在使用 MSP430FR2155、我希望每隔一小时进行一些计算并更新这些值。 我想创建一个计时器中断、可用于执行这些计算。 或者、是否有任何函数可以产生一个小时的延迟?

此外、我想知道使用计时器中断和相关的必要设置可以实现的最大延迟是多少。

我该如何处理?

感谢任何帮助。  

提前感谢!

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

    这取决于您的时钟。 但您可以通过使用较短的延迟来获得几乎任何的延迟、只需等待其中的 N 个小时即可。 例如、如果延迟为1秒、则在每个中断中会递增一个计数器。 一旦到达3600,您将执行操作,并将计数器设回0。

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

    您好!

    Keith 讲得很好。  要延迟一小时、您可能需要更频繁地唤醒并实施计数器。  为此、我可能建议使用 RTC。  您可以轻松地将 RTC 计时器配置为每秒或每分钟唤醒一次、然后将其计数到更长的时间段。   

    祝你好运!

    JD

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

    嗨、Keith

    感谢您的建议。 我不熟悉中断的概念。 您建议的逻辑是否有示例代码?

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

    您好、JD、

    此外、我对 RTC 也非常陌生、所以您提到的函数是否有任何示例代码或我可以参考的任何线程?  

    我昨天才知道了 RTC、在 TI 的 Resource Explorer 中搜索了相同的示例。 但我没有找到任何。

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

    Resource Explorer 中有大量示例。 下面有一个(msp430fr235X_lpm4_5_02.c)使用 RTC 每秒生成一个中断(需要32K 的晶体):

    //******************************************************************************
    //   MSP430FR235x Demo - LPM3.5, device enter LPM3.5 and toggles P1.0 with
    //                       RTC interrupt handling every 1s
    //
    //
    //   Description: Device enter LPM3.5 after configuring the RTC. The RTC wakes
    //   the device up from LPM3.5 every second and toggles P1.0.
    //   It also stores the state of P0OUT in the Backup RAM Registers.
    //
    //   ACLK = XT1 = 32kHz, MCLK = SMCLK = default DCODIV = ~1MHz.
    //
    //            MSP430FR2355
    //         -----------------
    //     /|\|                 |
    //      | |                 |
    //      | |        XIN(P2.7)|--
    //      --|RST              |  ~32768Hz
    //        |       XOUT(P2.6)|--
    //        |                 |
    //        |             P1.0|-->LED
    //
    //   Cash Hao
    //   Texas Instruments Inc.
    //   November 2016
    //   Built with IAR Embedded Workbench v6.50.0 & Code Composer Studio v6.2.0
    //******************************************************************************
    #include <msp430.h>
    
    void initGpio(void);
    
    int main(void)
    {
        WDTCTL = WDTPW | WDTHOLD;               // Stop WDT
    
        initGpio();                             // Configure GPIO
    
        // Initialize XT1 32kHz crystal
        P2SEL1 |= BIT6 | BIT7;                  // P2.6~P2.7: crystal pins
        do
        {
            CSCTL7 &= ~(XT1OFFG | DCOFFG);      // Clear XT1 and DCO fault flag
            SFRIFG1 &= ~OFIFG;
        } while (SFRIFG1 & OFIFG);              // Test oscillator fault flag
    
        // First determine whether we are coming out of an LPMx.5 or a regular RESET.
        if (SYSRSTIV == SYSRSTIV_LPM5WU)        // When woken up from LPM3.5, reinit
        {
            // If MCU wakes up from LPM3.5, re-init and then return to LPM3.5 again.
    
            // Restore P1OUT value from backup RAM memory, keep P1OUT after LPMx.5 reset
            P1OUT = *(unsigned int *)BKMEM_BASE;
    
            __enable_interrupt();               // The RTC interrupt should trigger now...
        }
        else
        {
            // Device powered up from a cold start.
            // It configures the device and puts the device into LPM3.5
    
            // Configure backup memory
            *(unsigned int *)BKMEM_BASE = 0;
    
            // Configure RTC
            // Interrupt and reset happen every 1024/32768 * 32 = 1 sec.
            RTCMOD = 32-1;
            RTCCTL = RTCSS__XT1CLK | RTCSR |RTCPS__1024;
            RTCCTL |= RTCIE;
    
            // Store P1OUT value in backup memory register before enter LPM3.5
            *(unsigned int *)BKMEM_BASE = P1OUT;
        }
    
        // Enter LPM3.5 mode with interrupts enabled. Note that this operation does
        // not return. The LPM3.5 will exit through a RESET event, resulting in a
        // re-start of the code.
        PMMCTL0_H = PMMPW_H;                    // Open PMM Registers for write
        PMMCTL0_L |= PMMREGOFF;                 // and set PMMREGOFF
        __bis_SR_register(LPM3_bits | GIE);
        __no_operation();
    
        return 0;
    }
    
    void initGpio()
    {
        P1DIR = 0xFF; P2DIR = 0xFF; P3DIR = 0xFF; P4DIR = 0xFF; P5DIR = 0xFF; P6DIR = 0xFF;
        P1REN = 0xFF; P2REN = 0xFF; P3REN = 0xFF; P4REN = 0xFF; P5REN = 0xFF; P6REN = 0xFF;
        P1OUT = 0x00; P2OUT = 0x00; P3OUT = 0x00; P4OUT = 0x00; P5OUT = 0x00; P6OUT = 0x00;
    
        // Disable the GPIO power-on default high-impedance mode
        // to activate previously configured port settings
        PM5CTL0 &= ~LOCKLPM5;
    }
    
    #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, RTCIV_RTCIF))
        {
            case RTCIV_NONE : break;            // No interrupt pending
            case RTCIV_RTCIF:                   // RTC Overflow
                // Toggle LED on P1.0
                P1OUT ^= BIT0;
    
                // Store P1OUT value in backup memory register
                *(unsigned int *)BKMEM_BASE = P1OUT;
                break;
            default:          break;
        }
    }
    

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

    太好了!

    谢谢 Keith。 将使用该代码进行一次检查