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.

UART MSP430G2553

 

#include <msp430.h>
#include <stdint.h>
#include <stddef.h>
//#include "menu.h"

int uart_puts(const char *str);
int uart_getchar(void);
int uart_putchar(int c);
int get_time(const char *str);


void initports();
volatile char Flag=0;
//const char string1[] = { "Enter the Time in This Format hh:mm:ss \r\n" };
char str1[3];
char str2[3];
char str3[3];

char i;
char rx=0;
//char k = 0;
char j = 0;


int main(void)
{
  WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT
  if (CALBC1_1MHZ==0xFF)					// If calibration constant erased
  {
    while(1);                               // do not load, trap CPU!!
  }
  DCOCTL = 0;                               // Select lowest DCOx and MODx settings
  BCSCTL1 = CALBC1_1MHZ;                    // Set DCO
  DCOCTL = CALDCO_1MHZ;
  P1SEL = BIT1 + BIT2 ;                     // P1.1 = RXD, P1.2=TXD
  P1SEL2 = BIT1 + BIT2 ;                    // P1.1 = RXD, P1.2=TXD
  UCA0CTL1 |= UCSSEL_2;                     // SMCLK
  UCA0BR0 = 104;                            // 1MHz 9600
  UCA0BR1 = 0;                              // 1MHz 9600
  UCA0MCTL = UCBRS0;                        // Modulation UCBRSx = 1
  UCA0CTL1 &= ~UCSWRST;                     // **Initialize USCI state machine**
  IE2 |= UCA0RXIE;                          // Enable USCI_A0 RX interrupt

 initports();


 while(1){
	 if (Flag==1){
                 uart_puts("\n**********************************************");
                 uart_puts("\nCurrent DATE and TIME as per your Computer is");
                 uart_puts("\n"__DATE__);
                 uart_puts("\n"__TIME__);
                 uart_puts("\n**********************************************\n");

                 const char *prompt=  "Enter to Take this as current time : y for YES or n for NO: ";

                  uart_puts(prompt);

                   while (rx==0) { // IFG2 |= UCA0RXIFG;
int c;
//                	  do {
               		  c = uart_getchar();
//                	  }
//                	  while((c!='y')||(c!='n'));


                         if (c == 'y') {
                        	 rx=1;P2OUT &=~BIT0;
                             uart_putchar(c);
                             uart_puts("\n");
                             uart_puts(__TIME__"\n");
                             get_time(__TIME__);

                             uart_puts("\n");
                             uart_puts(str1);
                             uart_puts("\n");

                             uart_puts("\n");
							 uart_puts(str2);
							 uart_puts("\n");

							 uart_puts("\n");
							 uart_puts(str3);
							 uart_puts("\n");

                         } else if ((c == '\n') || (c == '\r')) {
                             uart_puts("\n");
                             uart_putchar(c);
                             break;
                         } else if  (c == 'n') {
                        	 uart_putchar(c);
                        	 uart_puts("\nBetter luck next Time\r");
                        	 /* Not a valid character */
                         }else  {/* Not a valid character */
                         }
                     }
//
                    Flag=0;




//                 IE2 &= ~UCA0TXIE;
//
//while(1){
//	if (Flag==1){
// Flag=0; P1OUT &= ~BIT0;
// unsigned int value = 0;
// IE2 &= ~UCA0TXIE;
// IE2 &= ~UCA0RXIE;
//
// int c=uart_getchar();
//     uart_putchar(c);
//
//     if ((c >= '0') && (c <= '9')) {
//                 value *= 10;
//                 value += c - '0';
//                 uart_putchar(c);
//             } else if ((c == '\n') || (c == '\r')) {
//                 uart_puts("\n");
//                 //break;
//             }
//
	}
  __bis_SR_register(LPM0_bits + GIE);       // Enter LPM0, interrupts enabled
  }

}

void initports()
{
	P2DIR |=  BIT0;
	P2OUT &= ~BIT0;
	P2IES |= 0xFF; 					//Interrupt on high-to-low
	P2IE |= BIT3; 					//Port 1 is interruptible
	P2REN |=BIT3;
	P2OUT |=BIT3;
	//P1SEL &= 0x00; 					//No functions


	return;
}


int get_time(const char *str)
{
    int status = -1;
    int x=0;

    if (str != NULL) {
        status = 0;

        while (*str != ':') {
            /* Wait for the transmit buffer to be ready */
            while (!(IFG2 & UCA0TXIFG));
            /* Transmit data */
            str1[x++] = *str;

            str++;
        }

        str++;x=0;
        while (*str != ':') {
                   /* Wait for the transmit buffer to be ready */
                   while (!(IFG2 & UCA0TXIFG));
                   /* Transmit data */
                   str2[x++] = *str;

                   str++;
               }
        str++;x=0;
        while (*str != '\0') {
                   /* Wait for the transmit buffer to be ready */
                   while (!(IFG2 & UCA0TXIFG));
                   /* Transmit data */
                   str3[x++] = *str;

                   str++;
               }

    }

    return status;
}



int uart_puts(const char *str)
{
    int status = -1;

    if (str != NULL) {
        status = 0;

        while (*str != '\0') {
            /* Wait for the transmit buffer to be ready */
            while (!(IFG2 & UCA0TXIFG));

            /* Transmit data */
            UCA0TXBUF = *str;

            /* If there is a line-feed, add a carriage return */
            if (*str == '\n') {
                /* Wait for the transmit buffer to be ready */
                while (!(IFG2 & UCA0TXIFG));
                UCA0TXBUF = '\r';
            }

            str++;
        }
    }

    return status;
}

int uart_putchar(int c)
{
    /* Wait for the transmit buffer to be ready */
    while (!(IFG2 & UCA0TXIFG));

    /* Transmit data */
    UCA0TXBUF = (char ) c;

    return 0;
}


int uart_getchar(void)
{
    int chr = -1;

    if (IFG2 & UCA0RXIFG) {
        chr = UCA0RXBUF;
    }

    return chr;
}

#pragma vector=PORT2_VECTOR
__interrupt void    Port_2(void)
{
    Flag =1;
    P2OUT |=BIT0;
    P2IFG &= ~BIT3;
  //  IE2 |= UCA0RXIE;
	_bic_SR_register_on_exit(LPM0_bits);
}



I am trying to get time date serially through UART and the problem is that i am trying to use the interrrupt on port2 pin0 and thus starting the UART , but its not working with that thing otherwise its working fine.

please let me know the solution for it,

regards

Ankit Jain

 

**Attention** This is a public forum