在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次。
TIMEARA中配置的时间较为准确,不知道什么原因导致RTC差距很大。
Susan Yang:
参考用户指南 21.1 RTC Overview
https://www.ti.com.cn/cn/lit/ug/slau208q/slau208q.pdf
而
综上,可以使用的·
user791567:
回复 Susan Yang:
那这个和我配置的什么有关系呢??RTC中断进不去
Susan Yang:
回复 user791567:
请给出完整程序,我来测试一下,谢谢
user791567:
回复 Susan Yang:
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 flagUCSCTL4 = 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 outputP1DIR |= BIT0;// Set P1.0 as outputP1OUT &= ~BIT1;// Clear P1.0 outputP1DIR |= BIT1;// Set P1.0 as output// Configure RTC_CRTCCTL0_H = RTCKEY_H;// Unlock RTC_C moduleRTCCTL0_L |= RTCTEVIE | RTCMODE|RTCAIE | RTCRDYIE; // Enable RTC time event, alarm event,// read ready interruptRTCCTL1 |= RTCBCD | RTCHOLD;// RTC enable BCD mode, RTC holdRTCYEAR = 0x2011;// Year = 0x2011 = 2011RTCMON = 0x12;// Month = 0x12 = DecemberRTCDAY = 0x05;// Day = 0x05 = 5thRTCDOW = 0x03;// Day of week = 0x03 = WednesdayRTCHOUR = 0x24;// Hour = 0x12RTCMIN = 0x59;// Minute = 0x57RTCSEC = 0x55;// Seconds = 0x36RTCADOWDAY = 0x3;// RTC Day of week alarm = 0x2RTCADAY = 0x22;// RTC Day Alarm = 0x22RTCAHOUR = 0x23;// RTC Hour AlarmRTCAMIN = 0x45;// RTC Minute AlarmRTCCTL1 &= ~(RTCHOLD);// Start RTC calendar modeRTCCTL0_H = 0;// Lock RTC_C module__bis_SR_register(GIE);// Enter LPM3 w/ interrupts enabledwhile(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 interruptsbreak;case RTCIV_RTCOFIFG:// RTCOFIFGbreak;case RTCIV_RTCRDYIFG:// RTCRDYIFGP1OUT ^= 0x01;// Toggles P1.0 every secondbreak;case RTCIV_RTCTEVIFG:// RTCEVIFG__no_operation();// Interrupts every minutebreak;case RTCIV_RTCAIFG:// RTCAIFG__no_operation();// Interrupts every alarm eventbreak;case RTCIV_RT0PSIFG:// RT0PSIFGbreak;case RTCIV_RT1PSIFG:// RT1PSIFGbreak;case 14: break;// Reservedcase 16: break;// Reserveddefault: break;} }
你使用的是RTC的计数器模式,而不是日历的模式。你在日历模式试一下,我这边是很久才会进入一次中断,谢谢
Susan Yang:
回复 user791567:
好的,我会在下午测试后给您回复
Susan Yang:
回复 user791567:
user791567我这边是很久才会进入一次中断
能否详细描述一下?
我这边用下面的代码测试了一下,运行正常,P1.0每秒闪烁一下,而后会进入RTCEVIFG
#include <msp430.h>int main(void) {WDTCTL = WDTPW + WDTHOLD;// Stop Watchdog TimerP1DIR |= BIT0;// Set P1.0 as outputUCSCTL4 = SELM__REFOCLK + SELS__REFOCLK + SELA__REFOCLK;// MCLK = SMCLK = ACLK = REFOCLK// Configure RTC_ARTCCTL01 |= RTCTEVIE + RTCRDYIE + RTCBCD + RTCHOLD + RTCMODE;// RTC enable, BCD mode, RTC hold// enable RTC read ready interrupt// enable RTC time event interruptRTCYEAR = 0x2010;// Year = 0x2010RTCMON = 0x4;// Month = 0x04 = AprilRTCDAY = 0x05;// Day = 0x05 = 5thRTCDOW = 0x01;// Day of week = 0x01 = MondayRTCHOUR = 0x10;// Hour = 0x10RTCMIN = 0x32;// Minute = 0x32RTCSEC = 0x45;// Seconds = 0x45RTCADOWDAY = 0x2;// RTC Day of week alarm = 0x2RTCADAY = 0x20;// RTC Day Alarm = 0x20RTCAHOUR = 0x10;// RTC Hour AlarmRTCAMIN = 0x23;// RTC Minute AlarmRTCCTL01 &= ~(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 interruptsbreak;case RTC_RTCRDYIFG:// RTCRDYIFGP1OUT ^= 0x01;// Toggles P1.0 every secondbreak;case RTC_RTCTEVIFG:// RTCEVIFG__no_operation();// Interrupts every minutebreak;case RTC_RTCAIFG:// RTCAIFGbreak;case RTC_RT0PSIFG:// RT0PSIFGbreak;case RTC_RT1PSIFG:// RT1PSIFGbreak;case 12: break;// Reservedcase 14: break;// Reservedcase 16: break;// Reserveddefault: break;} }
user791567:
回复 Susan Yang:
我焊接XT1的晶振(32.768KHZ)的话也是会进入中断,如果去掉晶振RTC的中断就不进入了。使用的是MSP430F6723,使用上面的程序
user791567:
回复 Susan Yang:
能否去掉外部晶振进行测量呢?
Susan Yang:
回复 user791567:
我这边没有MSP430F6723的板子只有MSP430F5438A的板子,板子上已经固定了XT1,我回头找找其他板子来测试一下