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.

MSP30 launchpad: sending multiple char in UART, with each char must be sent only after acknowledgement

by the example , if char 'u' is received send "hello world".. we can write multiple if conditions if we will receive different characters and transmit accordingly.. but i have to transmit multiple characters and receive accordingly..

for example,

I have to send 'h', 'i' through UART.  first 'h' should be sent. if "OK" is received send "i".

how to write UCA0TX interrupt?

  • Don't put too much of data processing in Isr. It's too simple, compare d character h and send ok,and on receiving ok send next character which is I here.

  • ok.. 

    If microcontroller will be receiving "OK"..

    1)how to receive multiple characters?

    Is this code correct for receiving multiple characters?

    char stringr[]; is declared. 

    #pragma vector=USCIAB0RX_VECTOR
    __interrupt void USCI0RX_ISR(void)
    {
    stringr[ i ] = UCA0RXBUF;
    i++;
    }

    2)  how to compare whether the received characters are "OK"?

  • Karthikeyan Dhandapani said:
    how to compare whether the received characters are "OK"?

    if your acknowledgment string is always going to be "OK", you can compare the string of length 2 as below

    if(i==2){strncmp(stringr,"OK",2)}

    but this comparison will happen for all the data which is more than 2 bytes, so you can maintain a flag to say that you are expecting an acknowledgment and not data so,

    it becomes, if(i==2 && expecting_ACK == 1){strncmp(stringr,"OK",2)}

  • use a key variable to start comparison in string helps u.

    I used Enter here.

    #pragma vector=USCIAB0RX_VECTOR
    __interrupt void USCI0RX_ISR(void)
    {
    storedata[h++] = UCA0RXBUF;                       //String "storedata" is used to store Rx data
      if(storedata[h-1] == '\r')                                 //check if enter is pressed
        {

           storedata[h-1] = '\0';                                 //add null char to terminate string
           h=0; //reset address of data string
        }

     if(strcmp(storedata, prestring) == 0)           //Compare sting(here it is predefined and containing text)
    { P1OUT ^= 0x01;
                     // Toggle if string match. It can have any length     
    }

**Attention** This is a public forum