void InitializeRealTimeClock( void ) { Timer_Initialise(); // stop it RTCCTL01 = RTCHOLD; // use calibration data to adjust real time clock frequency if ( QueryCalibrationValid() ) { signed char RtcCalibrationValue = GetRtcCalibrationValue(); if ( RtcCalibrationValue < 0 ) { RtcCalibrationValue = -1 * RtcCalibrationValue; RTCCTL2 = RtcCalibrationValue & RTCCAL_VALUE_MASK; } else { RTCCTL2 = RtcCalibrationValue & RTCCAL_VALUE_MASK; /* adjust up */ RTCCTL2 |= RTCCALS; } } // Set the counter for RTC mode RTCCTL01 |= RTCMODE; // set 128 Hz rate for prescale 0 interrupt RTCPS0CTL |= RT0IP_7; // enable 1 pulse per second interrupt using prescale 1 RTCPS1CTL |= RT1IP_6 | RT1PSIE; // 1 Hz calibration output RTCCTL23 |= RTCCALF_3; // setting the peripheral selection bit makes the other I/O control a don't care // P2.4 = 1 Hz RTC calibration output // Direction needs to be set as output RTC_1HZ_PORT_SEL |= RTC_1HZ_BIT; RTC_1HZ_PORT_DIR |= RTC_1HZ_BIT; // These calls are to asm level patch functions provided by // TI for the MSP430F5438 SetRTCYEAR((unsigned int)0x07db); SetRTCMON((unsigned int)5); SetRTCDAY((unsigned int)23); SetRTCDOW((unsigned int)5); SetRTCHOUR((unsigned int)23); SetRTCMIN((unsigned int)58); SetRTCSEC((unsigned int)0); // Enable the RTC RTCCTL01 &= ~RTCHOLD; }
void InitRealTimeClock(void) { RtcInUseMask = 0; // stop it RTCCTL01 = RTCHOLD; // use calibration data to adjust real time clock frequency if (ValidCalibration()) { signed char RtcCalibrationValue = GetRtcCalibrationValue(); if (RtcCalibrationValue < 0) { RtcCalibrationValue = -RtcCalibrationValue; RTCCTL2 = RtcCalibrationValue & RTCCAL_VALUE_MASK; } else { RTCCTL2 = RtcCalibrationValue & RTCCAL_VALUE_MASK; /* adjust up */ RTCCTL2 |= RTCCALS; } } // Set RTC mode and BCD format RTCCTL01 |= RTCMODE | RTCBCD; // set 128 Hz rate for prescale 0 interrupt RTCPS0CTL |= RT0IP_7; // enable 1 pulse per second interrupt using prescale 1 RTCPS1CTL |= RT1IP_6 | RT1PSIE; // 1 Hz calibration output RTCCTL23 |= RTCCALF_3; // setting the peripheral selection bit makes the other I/O control a don't care // P2.4 = 1 Hz RTC calibration output // Direction needs to be set as output RTC_1HZ_PORT_SEL |= RTC_1HZ_BIT; RTC_1HZ_PORT_DIR |= RTC_1HZ_BIT; RestoreRtc(); // Enable the RTC RTCCTL01 &= ~RTCHOLD; }