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.

Serial port & LCD

Other Parts Discussed in Thread: MSP430FG4618

hi all,

   I am a newbie & this a dumb question. I am sending data from Matlab via serial port to MSP430FG4618 Exp's Board. This value is received as character in UCA0RXBUF. Can anyone tell me how to i convert the received value to integer so that it can be displayed on LCD.

For ex. if i send 1234 from Matlab this will be received as character on board. How do i change this value to integer.

Secondly if i want to use an array to store the received value how can that be achieved.

 

Thanks

Sid

  • sam22 said:

    I am sending data from Matlab via serial port to MSP430FG4618 Exp's Board. This value is received as character in UCA0RXBUF. Can anyone tell me how to i convert the received value to integer so that it can be displayed on LCD.

    For ex. if i send 1234 from Matlab this will be received as character on board. How do i change this value to integer.

    You will need to verify this, but I suspect that the MSP430 is receiving these characters as ASCII format.  You will need to perform an ASCII-to-Integer conversion.  You can find atoi() in stdlib.h.  I believe the string that is passed to the atoi() needs to be a null terminated string (ie. '\0').

     

    sam22 said:

    Secondly if i want to use an array to store the received value how can that be achieved.

    In order to store the received value into an array, you will need to first declare an array value.  The UCA0RXBUF in your interrupt service routine will need to be copied into the array with an index that you need to maintain.

     

    #define MAXNUMBERBYTES 16

    char RxBuff[MAXNUMBERBYTES] ;
    int RxBuffIndex = 0 ;

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

     

    The other portions of your program will need to check for a null terminated string in the array, or you could augment the interrupt service routine to check each character for a null character.  It could then set a flag to indicate a full string has been received.
    You will also need to manage RxBuffIndex to ensure it does not run beyond the size of RxBuff[].  Plus, once your program consumes the current value in RxBuff[], then it should reset RxBuffIndex back to 0.

     

**Attention** This is a public forum