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.

I want to receive a string or a character through UART in msp430g2553 but not able to receive even a single character it. If a character arrives my IFG2 flag is not getting set so what should i do in this code ?

Following is my routine code to receive a string.

void UART_GETSTRING(unsigned char * string, int length)
{
    unsigned int i=0;
    while(i<length)
        {
            string[i]=UART_GETCHAR();
            i++;
        }
}

unsigned char UART_getchar()                //Waits for a valid char from the UART
{

   check=0;
    IE2 |= UCA0RXIE;
while(1)
 {
     if(check==1)
     { check=0;
         break;
     }

 }

    IE2 &= ~UCA0RXIE;

    return rx_char;
}



#pragma vector=USCIAB0RX_VECTOR
__interrupt void USCI0RX_ISR(void)
{
  while (!(IFG2&UCA0RXIFG));                 // USCI_A0 TX buffer ready?
  rx_char=UCA0RXBUF;

  check=1;
}

  • harish yadav -

    You need to show your init code to make sure that the GPIO are setup correctly, and that the interrupts(UART and GIE) have been enabled.

    Go to :www.ti.com/.../MSP430G2553

    Click on Tools and Software - You will find a zip file that has UART code all packaged up for you.

    -Jason
  • This is my init code.
    void UART_INIT()
    {
    P1SEL= RXD+TXD;
    P1SEL2= RXD+TXD;

    DCOCTL = 0; // Select lowest DCOx and MODx settings
    BCSCTL1 = CALBC1_1MHZ; // Set DCO
    DCOCTL = CALDCO_1MHZ;
    UCA0CTL1 |= UCSSEL_2;
    UCA0CTL0 = 0x00;
    UCA0BR0=104; // presacalar value for BAUD rate generator 9600 bps (1MHZ/104=9600)
    UCA0BR1=0;
    UCA0CTL1 &=~UCSWRST; //initialize USCI state machine
    UCA0MCTL=UCBRS0; // modulation UCBRSx=1
    __bis_SR_register(CPUOFF + GIE); // Enter LPM0 w/ int until Byte RXed
    }
  • What equipment or device is sending the string that you expect to receive? How is your G2552 interfaced (hardware wise) to that equipment or device?

    For the G2553, I do not see how you initialize the UART and the UART pins. I also do not see how you set up SMCLK or ACLK.
  • I m using hypeterminal to send and receive the character and RS232 communication cable to interface. I have initialized SMCLK using UCA0CTL1 |= UCSSEL_2; command in init function. I have initialized port 1 in main function. My main function is as following:
    int main(void)
    {
    unsigned char trial;
    WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
    P1OUT=0x00;
    P1DIR=0xFF;
    _enable_interrupt();
    UART_INIT();
    while(1)
    {
    trial=UART_getchar();
    UART_PUTCHAR(trial);
    }
    }

    Using the same init function i have sent the character but not able to receive.
  • please help me. I did everything but not receiving any char.
  • The last thing UART_INIT does is put the MCU to sleep (CPUOFF). Your program will not proceed from here:
    1) RXIE isn't set, so even if a character arrives you won't reach the ISR
    2) The ISR doesn't do a wakeup (LPM0_EXIT) so the foreground will stay asleep.

    Also, make sure "check" and "rx_char" are declared "volatile".

    How are you doing the RS232 conversion? Double check the TX/RX pin definitions for your converter, since different chips use different conventions.
  • Thank you so much for help.

**Attention** This is a public forum