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.

MSP430FR5989: RTC issue

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, &currentTime, 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, &param);

}

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

  • Hello Pankaj,
    unless I have overlooked something, you're not unlocking the ports. Please keep in mind, after every power cycle or reset, the Ports need to be unlocked to apply the GPIO settings you're writing into the control registers.
    So somewhere in your code there should be PMM_unlockLPM5();
    Please see also a calendar mode driver lib code example for the RTC_C you can find under CCS Resource Explorer MSP430Ware - v:3.80.05.04 >> Libraries >> Driver Library >> MSP430FR5xx6xx >> Example Projects >> RTC_C >> rtc_c_ex1_calendarmode
    You can import the project automatically into your Workspace and create this way automatically a functional project.
    Not sure, whether this is the only problem of your code example, but please give it a try.

    Best regards
    Peter
  • I already used that it in main
  • Hi Peter,
    i tried the sample calendar RTC example and it worked fine. I checked my code and it looks like I might be doing some error in setting the clocks.
    I am running ESI module as well in my code so I have the following clock setting:
    DCO = 8MHz, MCLK = 8MHz, SMCLK = 2MHz and ACLK = 32768Hz (using external crystal)
    Also the LFXT is on drive 3 setting as suggested in example code.

    Please suggest what changes needs to be done?

    - Pankaj
  • Hello Pankaj,
    many thanks for the clarification on the unlocking of the GPIOs and the additional information. The FR5989 is equipped with the RTC_C RTC module, which has an exclusive connection to the 32kHz crystal oscillator signal. Thus your other settings for DCO, MCLK, SMCLK and ACLK should not matter.
    For me it is a bit difficult to check, what specifically goes wrong.
    The easiest option I see, is to monitor the resulting RTC_C register settings on your side at different stages, and compare them with the working RTC_C example settings. What I mean is stopping code execution, e.g. after finishing the RTC_C initialization, and view its control register settings, then, maybe after executing the rest of the code a while, and checking again, whether the control register settings have changed. I think that's the easiest way, as then you should immediately see the register settings differences.
    If you cannot observe any differences, then it will get more difficult, but let's take one step after another.

    Best regards
    Peter

**Attention** This is a public forum