主题中讨论的其他器件: MSP430WARE
尊敬的先生:
我正在使用 MSP430FR5989、但在使用 RTC RTC_C_setCalendarEvent 2分钟时、RTCTEVIFG 是我将获得的2秒。 另外、我使用的 RTC 警报也不能正常工作、RTCAIFG 是我在不适当的时间收到的。请先查看代码、然后向我提供解决方案。
#include "main.h"
unsigned char day、flag;
volatile Calendar newTime;
uint8_t sending _interval = 0;
/*********
*@简要设置 RTC
(小部分 /
void setupRTC (void)
{
/*结构体传递到 RTC_C_CalendarInit()*/
日历日历日历日历日历时间;
/*
*选择端口 J
*将引脚4、5设置为输入主模块功能 LFXT。
*
GPIO_setPeripheralModuleFunctionInputPin (
GPIO_PORT_PJ、
GPIO_PIN4 + GPIO_PIN5、
GPIO_PRIMARY_MODULE_FUNCTION
);
/*初始化日历结构*/
calendarTime.seconds = 0;
calendarTime.minutes = 4;
calendarTime.hours = 16;
calendarTime.DayOfWeek = 3;
calendarTime.dayofmonth=24;
calendarTime.Month = 10;
CalendarTime.Year = 2018;
/*初始化 RTC 的日历模式
RTC_C 的基地址
*在当前时间内通过、在上面进行了初始化
*使用 BCD 作为日历寄存器格式
*
RTC_C_initCalendar (RTC_Selection、&日历 Time、RTC_C_FORMAT_BCD);
//清除中断
RTC_C_clearInterrupt (RTC_Selection、
RTC_C_CLOCK_READ_READY_INTERRUPT +
RTC_C_TIME_EVENT_INTERRUPT +
RTC_C_CLOCK_ALARM_INTERRUPT
);
//启用 RTC 就绪状态中断,当 RTC 时该中断有效
//Calendar 寄存器已准备好读取。
//此外,为日历警报和日历事件启用中断。
RTC_C_enableInterrupt (RTC_Selection、
RTC_C_CLOCK_READ_READY_INTERRUPT +
RTC_C_TIME_EVENT_INTERRUPT +
RTC_C_CLOCK_ALARM_INTERRUPT
);
//启动 RTC 时钟
RTC_C_startClock (RTC_Selection);
date_time.sec = 0;
DATE_TIME.min = 48;
DATE_TIME.Hour = 15;
DATE_TIME.WEEK = 3;
DATE_TIME.DAY = 24;
DATE_TIME.MONTH = 10;
DATE_TIME.year = 2018;
}
空 synctc (空)
{
//此函数将 RTC 日历时间与 NFC 提供的日期和时间同步
/*结构体传递到 RTC_C_CalendarInit()*/
日历当前时间;
/*初始化日历结构*/
CurrentTime.seconds = date_time.sec;
CurrentTime.minutes = DATE_TIME.min;
CurrentTime.hours = DATE_TIME.Hour;
CurrentTime.DayOfWeek = DATE_TIME.Week;
CurrentTime.dayofmonth = DATE_TIME.day;
CurrentTime.Month = DATE_TIME.Month;
CurrentTime.Year = DATE_TIME.year;
/*初始化 RTC 的日历模式
RTC_C 的基地址
*在当前时间内通过、在上面进行了初始化
*使用 BCD 作为日历寄存器格式
*
RTC_C_initCalendar (RTC_Selection、&CurrentTime、RTC_C_FORMAT_BCD);
//启动 RTC 时钟
RTC_C_startClock (RTC_Selection);
}
void setAlarm (void)
{
//设置每周12:00的星期日的日历报警
//注意:不指定一周的日期。
RTC_C_CONFIGureCalendarAlarmParam ={0};
param.minutesAlarm = RTC_C_ALARMCONDITION_OFF;
param.hoursAlarm = RTC_C_ALARMCONDITION_OFF;
param.dayOfWeekAlarm = 0x00;
param.dayOfMonthAlarm = RTC_C_ALARMCONDITION_OFF;
RTC_C_CONFIGureCalendarAlarm (RTC_Selection、¶m);
}
void flowAlert (void)(空)
{
if (myApp.ulLivePulseCount > 73500)
{
Status2.MS.over_Flow_Alert = 0x01;
}
否则、如果(myApp.ulLivePulseCount < 73500 && myApp.ulLivePulseCount!= 0x00)
{
Status2.MS.Low_Flow_Alert = 0x01;
}
}
//
//
//! \brief 初始化数据发送时间间隔。
//!
//! 此函数使用初始化日历事件、以便定期发送数据
//! RTC_C 模块的 setCalendarEvent。
//!
//! \param type 定义要发送的周期类型。
//! 有效值为:
//! -\b 分钟周期
//! -\b 每小时周期
//!
//! \param 值是发送前等待的时间量。
//! -\b 接受0到60的整数
//!
//! \无返回
//
//
空周期 SendingConfig (uint8_t 类型、uint8_t 值)
{
if (类型)
{
/*设置单个指定的日历中断条件*/
//指定一个中断以每小时生效
RTC_C_setCalendarEvent (RTC_Selection、RTC_C_CALENDAREVENT_HOURCHANGE);
}
其他
{
/*设置单个指定的日历中断条件*/
//指定一个中断以每分钟生效
RTC_C_setCalendarEvent (RTC_Selection、RTC_C_CALENDAREVENT_INTOTECHANGE);
}
//发送间隔设置
sending _interval =值;
}
//
//
//! \brief 根据配置定期发送数据。
//!
//! 此函数根据用户设置的时间发送定期数据
//!
//! \无返回
//
//
空周期终止(空)
{
静态 uint8_t sending _counter = 0;
if (sending _counter = sending _interval)
{
myApp.data_sent = 0x01;
sending _counter = 0;
}否则{
发送计数器++;
}
}
// RTC 应在轻触电话且 SETBIT = 1时更新,否则不更新
//每次需要时间发送数据时都要花费 RTC 时间
#if defined (__TI_Compiler_version__)|| Defined (__IAR_systems_ICC__)
#pragma vector=RTC_vector
_interrupt
#Elif defined (_GNU_)
__attribute__((中断(RTC_Vector))
#endif
空 RTC_ISR (空)
{
开关(__evo_in_range (RTCIV、16))
{
情况0:中断;//无中断
案例2://RTCRDYIFG
中断;
案例4://RTCTEVIFG
//每分钟或每小时中断一次
periodicSending ();
中断;
案例6://RTCAIFG
//interrupts 12:00 on 0th day of Week、即 Sunday
flowAlert();
中断;
案例8:中断;//RT0PSIFG
案例10:中断;//RT1PSIFG
案例12:中断;//保留
案例14:中断;//保留
案例16:中断;//保留
默认值:break;
}
}
谢谢、此致、
Pankaj