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.
Hello,
I am currently working on following code. But I couldn't read the RTCSEC. Also when I debug it, I found that CPU is not reaching ISR. I want to send RTC registers on UART.
void main(void)
{
WDTCTL = WDTPW | WDTHOLD; // Stop WDT
UCS_config(); // Clock Source system
/***************RTC Configuration with Calender Mode*********************/
RTCCTL0_H = RTCKEY_H; // Unlock RTC_C module
RTCCTL0_L |= RTCTEVIE | RTCAIE | RTCRDYIE; // Enable RTC time event, alarm event,
// read ready interrupt
RTCCTL1 |= RTCBCD | RTCHOLD; // RTC enable BCD mode, RTC hold
RTCYEAR = 0x2015; // Year 2015->0x2015
RTCMON = 0x08; // Month August->0x08
RTCDAY = 0x28; // Day 28th->0x28
RTCDOW = 0x05; // Day of week Friday-> 0x05
RTCHOUR = 0x24; // Hour from 24 Hour Mode
RTCMIN = 0x59; // Minute
RTCSEC = 0x55; // Seconds
/*****Alarm Registers*****/
RTCADOWDAY = 0x3; // RTC Day of week alarm = 0x2
RTCADAY = 0x22; // RTC Day Alarm = 0x22
RTCAHOUR = 0x23; // RTC Hour Alarm
RTCAMIN = 0x45; // RTC Minute Alarm
RTCCTL1 &= ~(RTCHOLD); // Start RTC calendar mode
RTCCTL0_H = 0; // Lock RTC_C module
P1DIR &= ~BIT6;
P1OUT |= BIT6;
eUSCI_A0_UART_config();
__bis_SR_register(GIE);
}
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=USCI_A0_VECTOR
__interrupt
void USCI_A0_ISR(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(USCI_A0_VECTOR))) USCI_A0_ISR (void)
#else
#error Compiler not supported!
#endif
{
switch (__even_in_range(UCA0IV, 8))
{
case USCI_NONE:
break; // No interrupt
case USCI_UART_UCRXIFG: // RXIFG
break;
case USCI_UART_UCTXIFG:
code for send data on UART....
break; // TXIFG
case USCI_UART_UCSTTIFG:
break; // TTIFG
case USCI_UART_UCTXCPTIFG:
break; // TXCPTIFG
default: break;
}
}
void eUSCI_A0_UART_config(void)
{
// Setup P3.0 UCA0RXD, P3.1 UCA0TXD
P3SEL0 |= BIT0 | BIT1; // Set P3.0, P3.1 to non-IO
P3DIR |= BIT0 | BIT1; // Enable UCA0RXD, UCA0TXD
// Setup eUSCI_A0
UCA0CTLW0 |= UCSWRST; // **Put state machine in reset**
UCA0CTLW0 |= UCSSEL_1; // CLK = ACLK
UCA0BRW=0x0003; // Clock Prescaler Setting baud-rate 32kHz/9600=3.41 (see User's Guide)
UCA0MCTLW = 0x5300; // Modulation UCBRSx=0x53, UCBRFx=0
UCA0CTLW0 &= ~UCSWRST; // **Initialize USCI state machine**
UCA0IE |= UCTXIE|UCRXIE; // Enable USCI_A0 RX/TX interrupt
}
#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 interrupts
break;
case RTCIV_RTCOFIFG: // RTCOFIFG
break;
case RTCIV_RTCRDYIFG: // RTCRDYIFG
{
volatile int sec=RTCSEC;
P1OUT ^= 0x40; // Toggles P1.6 every second
}
break;
case RTCIV_RTCTEVIFG: // RTCEVIFG
__no_operation(); // Interrupts every minute
break;
case RTCIV_RTCAIFG: // RTCAIFG
__no_operation(); // Interrupts every alarm event
break;
case RTCIV_RT0PSIFG: // RT0PSIFG
break;
case RTCIV_RT1PSIFG: // RT1PSIFG
break;
// case 14: break; // Reserved
case 16: break; // Reserved
default: break;
}
}
Please kindly resolve this issue. Is it because I have included two ISRs?
Thank you.
Abhi
Hello Jace,
But in my hardware there is no provision for any backup power or secondary supply. So I want to ask that still I need to go for LPM routine? I found the sample code from the MSPWARE for the RTC_C implementation. Find my edited code as follows:
main()
{
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
// Initialize LFXT1
UCSCTL6 &= ~(XT1OFF); // Enable XT1
UCSCTL6 |= XCAP_3; // Internal load cap
P3OUT &= ~BIT0; // Clear P3.0 output
P3DIR |= BIT0; // Set P3.0 as output
RTC_config();
__bis_SR_register(GIE);
__no_operation();
return 0;
}
void RTC_config()
{
RTCCTL0_H = 0xA5;
RTCCTL1 |= RTCBCD | RTCMODE;
RTCYEAR = 0x2015;
RTCMON = 0x05;
RTCDAY = 0x01;
RTCDOW = 0x02;
RTCHOUR = 0x01;
hr=RTCHOUR;
RTCMIN = 0x03;
min=RTCMIN;
RTCSEC = 0x00;
sec=RTCSEC;
RTCCTL0_L |= RTCTEVIE | RTCAIE | RTCRDYIE;
RTCCTL1 &= ~(RTCHOLD);
X=RTCCTL0_L;
sec=RTCSEC;
min=RTCMIN;
hr=RTCHOUR;
}
#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 interrupts
break;
case RTCIV_RTCOFIFG: // RTCOFIFG
break;
case RTCIV_RTCRDYIFG: // RTCRDYIFG
P3OUT ^= 0x01; // Toggles P3.0 every second
break;
case RTCIV_RTCTEVIFG: // RTCEVIFG
__no_operation(); // Interrupts every minute
break;
case RTCIV_RTCAIFG: // RTCAIFG
__no_operation(); // Interrupts every alarm event
break;
case RTCIV_RT0PSIFG: // RT0PSIFG
break;
case RTCIV_RT1PSIFG: // RT1PSIFG
break;
case 16: break; // Reserved
default: break;
}
}
But, even in this implementation, I am unable to pass current value to the var sec,min,hr from the already initialized RTC_registers. It keeps on reading 0(zero). Can you debug what is the problem poised?
Thank you.
Regards,
Abhi
Abhi,
You have to either go into an LPM state or have a while(1) [or some other main loop] within your main function. Without this, you hit the return 0 and exit the main function and the device is no longer executing code.
Example:
main() { //Initialization Code //RTC initialization //Application Code __bis_SR_register(GIE); //Enable Interrupts, if you want to you can go to LPM instead here as well while(1); __no_operation(); // Code should never get here }
This would be step one in debugging your code. For further hints on the RTC_C module, please see our TI Design:
Also, when posting code on the forums, please use the Rich Text Format Link on the bottom right hand side. From this advanced menu, please use the Insert Code Snippet function in order to format code for easier reading.
Regards,
JH
Hi Jace,
Thank you for the insight. I had followed your instruction and try for following code.
int main(void)
{
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
// Initialize LFXT1
UCSCTL6 &= ~(XT1OFF); // Enable XT1
UCSCTL6 |= XCAP_3; // Internal load cap
P3OUT &= ~BIT0; // Clear P3.0 output
P3DIR |= BIT0; // Set P3.0 as output
RTC_config();
__bis_SR_register(GIE);
while(1)
__no_operation();
}
void RTC_config()
{
// Configure RTC_C
RTCCTL0_H = RTCKEY_H; // Unlock RTC_C module
RTCCTL1 |= RTCBCD; // RTC enable BCD mode, RTC hold
RTCYEAR = 0x2015; // Year = 0x2015 -> 2015
RTCMON = 0x05; // Month = 0x09 -> September
RTCDAY = 0x01; // Day = 0x01 -> 1st
RTCDOW = 0x02; // Day of week -> 0x02
RTCHOUR = 0x01; // Hour = 0x13
hr=RTCHOUR;
RTCMIN = 0x30; // Minute = 0x30
min=RTCMIN;
RTCSEC = 0x00;
sec=RTCSEC; // Seconds = 0x00
RTCCTL0_L |= RTCTEVIE | RTCAIE | RTCRDYIE;
RTCCTL1 &= ~(RTCHOLD); // Start RTC calendar mode
// RTCCTL0_H = 0; // Lock RTC_C module
X=RTCCTL0_L;
sec=RTCSEC;
min=RTCMIN;
hr=RTCHOUR;
}
#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 interrupts
break;
case RTCIV_RTCOFIFG: // RTCOFIFG
break;
case RTCIV_RTCRDYIFG: // RTCRDYIFG
{
P3OUT ^= 0x01; // Toggles P3.0 every second
}
break;
case RTCIV_RTCTEVIFG: // RTCEVIFG
__no_operation(); // Interrupts every minute
break;
case RTCIV_RTCAIFG: // RTCAIFG
__no_operation(); // Interrupts every alarm event
break;
case RTCIV_RT0PSIFG: // RT0PSIFG
break;
case RTCIV_RT1PSIFG: // RT1PSIFG
break;
// case 14: break; // Reserved
case 16: break; // Reserved
default: break;
}
}
but still debugger shows the value of the var=0 even after starting it. Can you tell me what could be the problem?
Thank you.
Abhi
**Attention** This is a public forum