您好、TI 专家!
我正在使用 MSP430FR2155、我希望每隔一小时进行一些计算并更新这些值。 我想创建一个计时器中断、可用于执行这些计算。 或者、是否有任何函数可以产生一个小时的延迟?
此外、我想知道使用计时器中断和相关的必要设置可以实现的最大延迟是多少。
我该如何处理?
感谢任何帮助。
提前感谢!
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.
您好、TI 专家!
我正在使用 MSP430FR2155、我希望每隔一小时进行一些计算并更新这些值。 我想创建一个计时器中断、可用于执行这些计算。 或者、是否有任何函数可以产生一个小时的延迟?
此外、我想知道使用计时器中断和相关的必要设置可以实现的最大延迟是多少。
我该如何处理?
感谢任何帮助。
提前感谢!
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; } }