Part Number: MSP430FR5989
Other Parts Discussed in Thread: MSP430WARE
Dear sir,
i am using MSP430FR5989 but while using RTC RTC_C_setCalendarEvent for 2min,RTCTEVIFG is i am getting for 2 seconds. Also i am using RTC alarm that is also not working properly,RTCAIFG is i am getting at inappropriate time.Please once have a look on the code and kindly provide me solution.
#include "main.h"
unsigned char DAY,flag;
volatile Calendar newTime;
uint8_t sending_interval = 0;
/*****************************************************************************
* @brief Sets up the RTC
*****************************************************************************/
void setupRTC(void)
{
/* Struct to pass to RTC_C_CalendarInit() */
Calendar calendarTime;
/*
* Select Port J
* Set Pin 4, 5 to input Primary Module Function, LFXT.
*/
GPIO_setAsPeripheralModuleFunctionInputPin(
GPIO_PORT_PJ,
GPIO_PIN4 + GPIO_PIN5,
GPIO_PRIMARY_MODULE_FUNCTION
);
/* Initialize the Calendar struct */
calendarTime.Seconds = 0;
calendarTime.Minutes = 4;
calendarTime.Hours = 16;
calendarTime.DayOfWeek = 3;
calendarTime.DayOfMonth = 24;
calendarTime.Month = 10;
calendarTime.Year = 2018;
/* Initialize Calendar Mode of RTC
* Base Address of the RTC_C
* Pass in current time, intialized above
* Use BCD as Calendar Register Format
*/
RTC_C_initCalendar(RTC_SELECTION, &calendarTime, RTC_C_FORMAT_BCD);
// Clear interrupts
RTC_C_clearInterrupt(RTC_SELECTION,
RTC_C_CLOCK_READ_READY_INTERRUPT +
RTC_C_TIME_EVENT_INTERRUPT +
RTC_C_CLOCK_ALARM_INTERRUPT
);
//Enable interrupt for RTC Ready Status, which asserts when the RTC
//Calendar registers are ready to read.
//Also, enable interrupts for the Calendar alarm and Calendar event.
RTC_C_enableInterrupt(RTC_SELECTION,
RTC_C_CLOCK_READ_READY_INTERRUPT +
RTC_C_TIME_EVENT_INTERRUPT +
RTC_C_CLOCK_ALARM_INTERRUPT
);
//Start RTC Clock
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 ;
}
void syncRTC(void)
{
// The function syncs the RTC calendar time with NFC provided date and time
/* Struct to pass to RTC_C_CalendarInit() */
Calendar currentTime;
/* Initialize the Calendar struct */
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;
/* Initialize Calendar Mode of RTC
* Base Address of the RTC_C
* Pass in current time, intialized above
* Use BCD as Calendar Register Format
*/
RTC_C_initCalendar(RTC_SELECTION, ¤tTime, RTC_C_FORMAT_BCD);
//Start RTC Clock
RTC_C_startClock(RTC_SELECTION);
}
void setAlarm(void)
{
//Setup Calendar Alarm for 12:00 of Sunday every week
//Note: Does not specify day of the week.
RTC_C_configureCalendarAlarmParam param = {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;
}
else if(myApp.ulLivePulseCount < 73500 && myApp.ulLivePulseCount != 0x00)
{
Status2.MS.Low_Flow_Alert = 0x01;
}
}
//*****************************************************************************
//
//! \brief Initializes the data sending timeinterval.
//!
//! This function initializes calendar event for periodic data sending using the
//! setCalendarEvent of the RTC_C module.
//!
//! \param type defines the type of periodicity to send.
//! Valid values are:
//! - \b MINUTE_PERIODICITY
//! - \b HOURLY_PERIODICITY
//!
//! \param value is the quantum of time you want to wait before sending.
//! - \b accepts integers from 0 to 60
//!
//! \return None
//
//*****************************************************************************
void periodicSendingConfig(uint8_t type, uint8_t value)
{
if(type)
{
/* Set a single specified Calendar interrupt condition */
//Specify an interrupt to assert every hour
RTC_C_setCalendarEvent(RTC_SELECTION, RTC_C_CALENDAREVENT_HOURCHANGE);
}
else
{
/* Set a single specified Calendar interrupt condition */
//Specify an interrupt to assert every minute
RTC_C_setCalendarEvent(RTC_SELECTION, RTC_C_CALENDAREVENT_MINUTECHANGE);
}
// sending interval set
sending_interval = value;
}
//*****************************************************************************
//
//! \brief sends periodic data according to configuration.
//!
//! This function sends periodic data according to the time set by user
//!
//! \return None
//
//*****************************************************************************
void periodicSending(void)
{
static uint8_t sending_counter = 0;
if(sending_counter == sending_interval)
{
myApp.data_sent == 0x01;
sending_counter = 0;
} else {
sending_counter++;
}
}
// RTC should be updated when phone is tapped and SETBIT = 1, otherwise dont update
// take RTC time every time you need time to send data
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=RTC_VECTOR
__interrupt
#elif defined(__GNUC__)
__attribute__((interrupt(RTC_VECTOR)))
#endif
void RTC_ISR (void)
{
switch (__even_in_range(RTCIV,16))
{
case 0: break; //No interrupts
case 2: //RTCRDYIFG
break;
case 4: //RTCTEVIFG
//Interrupts every minute or hour
periodicSending();
break;
case 6: //RTCAIFG
//Interrupts 12:00 on 0th day of week i.e. Sunday
flowAlert();
break;
case 8: break; //RT0PSIFG
case 10: break; //RT1PSIFG
case 12: break; //Reserved
case 14: break; //Reserved
case 16: break; //Reserved
default: break;
}
}
Thanks and Regards,
Pankaj