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 Receive MSP430

Other Parts Discussed in Thread: MSP430G2553

//START OF CODE 1

      

SendString("ATE0\r\n");

 

 

              i=0;

              do {

 

                     while(!(IFG2&UCA0RXIFG));

                     Received [i] = UCA0RXBUF;

                     i++;

 

              } while (Received [i-1] != 'K');

// END of CODE 1

 

//START OF CODE 2

 

 

             

              while(!(IFG2&UCA0RXIFG));

              Received [0] = UCA0RXBUF;

              while(!(IFG2&UCA0RXIFG));

              Received [1] = UCA0RXBUF;

              while(!(IFG2&UCA0RXIFG));

              Received [2] = UCA0RXBUF;

              while(!(IFG2&UCA0RXIFG));

              Received [3] = UCA0RXBUF;

              while(!(IFG2&UCA0RXIFG));

              Received [4] = UCA0RXBUF;

              while(!(IFG2&UCA0RXIFG));

              Received [5] = UCA0RXBUF;

 

              */

 

 

//END OF CODE 2

 

 

Im using the following two segments of code ( CODE 1 and CODE 2) to capture UART characters coming out of SIM908 ( a GSM MODULE) . The code 2 works perfectly! however the CODE 1 does. Im wondering why and I cant seem to figure why.

I am using MSP430G2553. In the First Code ( the one that doest work), the character array ‘Received [ ]’ gets nothing. Is this possible? But it somehow passes the check “while (Received [i-1] != 'K');” and goes to the next execution point in debugging and I know for a fact that DO WHILE loop is executed.

 I don’t like Code 2 because it’s not so professional. It also would use up 100 lines of code to receive 50 characters. So I would like to know a way to improve the UART Receiving code. Has anyone got a better approach to receive UART characters using MSP430G2553? And no, I don’t want to use Interrupts, because I will have to be calling delays till my character array gets filled and I believe it’s not important in my application to go to sleep in-between receiving two characters.

 

Your responses would be appreciated so much.

  • char received[];

    for(i=16;i>0;i--)
    {
    while (!(IFG2&UCA0RXIFG));
    received[16-i] = UCA0RXBUF;
    }

    I didn't understand why you are using while (Received [i-1] != 'K'). As in you want to end the reception when K character is received? I wrote the above code for reception of multiple characters. It is working fine. I tested by sending the received[] array to a lcd. All the characters that I typed were displayed on the screen properly. So if you want to take 50 characters just change i=16 to 50 and received[16-i] to received[50-i].

  • Manpreet Singh Minhas said:
    I didn't understand why you are using while (Received [i-1] != 'K'). As in you want to end the reception when K character is received? I wrote the above code for reception of multiple characters. It is working fine. I tested by sending the received[] array to a lcd. All the characters that I typed were displayed on the screen properly. So if you want to take 50 characters just change i=16 to 50 and received[16-i] to received[50-i].

    Maybe her character sets aren't always 50 characters long, so detecting "K" as the terminator is needed.

    As for the question, I don't understand why CODE 1 doesn't work. I've tried the Do While loop with simple C program (take the Received [i] value from another array) and it worked well.

    Since you don't want to use interrupt, maybe you can try another approach, something like :

    K_flag = 0;
    i = 0;
    
    do
    {
        while (!(IFG2 & UCA0RXIFG));
    
        if (UCA0RXBUF == 'K')
            K_flag = 1;
        else
        {
            Received[i] = UCA0RXBUF;
            i++;
        }
    } while (K_flag == 0);

    That might work. If it doesn't, my thought is that the char comparison process doesn't worked as it supposed to be, which would be weird...

**Attention** This is a public forum