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 Communication via RS232

My problem is that I want to take a value from the ADC and the values are like 1233. I am using three ADC channels and I want to send the values to the hyperterminal.

I need to send the whole integer value. 

Is there any way by which I can send the whole integer because after seeing the help the only solution I could found was related only for sending single bits like 'A'.

Any help would be appreciated. 

  • Hello,

    The first solution: if you want to see "1233" value in terminal you need to change "1233" integer into string.

    The second solution: if you want to send raw integer you need to send two bytes, since every integer (16 bits) consists of 2 bytes (2x8 bits).

    Please note that you won't see "1233" in the terminal. 1233=0x04D1: 1st byte 0xD1 is a 'Ñ' character in ASCII table and 2nd byte 0x04 is an "End of Transmission" control character.

    Freeware "br@y terminal" app allows to see the raw data in bin, int and hex format.

    Best regards,

    Mikolaj

  • Thank you for your help.

    Only the problem is I don't want to convert it into string.

    I want to take the value from there to MATLAB for further analysis 

    So I just want to get the values directly from the TI ADC to MATLAB via RS232 

    I was able to transfer one bit but don't know if I can send a whole integer through that somehow.

  • bhanu pratap said:
    I was able to transfer one bit but don't know if I can send a whole integer through that somehow.

    RS232 transfers are byte by byte. If a sequence of two bytes shall form an integer, both, sender and receiver, must agree that it is so. The sender splits the integer into two bytes, and sends them. The receive rreceives two bytes and assembles them to an integer again.
    So both sides must know hoe the serial data is to be interpreted.

  • bhanu pratap said:
    I want to take the value from there to MATLAB

    So you need to study your MATLAB documentation to understand what MATLAB requires in order to receive serial data.

    Then you need to write your MSP430 code so that it sends whatever MATLAB requires.

  • Sir 

    With the MATLAB its easy . You just have to activate the port the problem lies with sending the data.

    I want to send an integer like 1233 but with RS232 I can only send the data byte by byte. 

    SO any method by which I could send the whole integer directly.

  • but for the integer like 1233 the number would have to be broken into 4 parts and then send each byte.

    That would make it a bit difficult for the analysis.

    Any other suggestions.

  • Hello, pratap

     U can't send integer value to the hyperterminal as it is . 

    For that you need to read as hexa decimal value (0x04D1)  and you can send .

  • So you want to say that by :-

    TXBUF1=0x04D1;

    I can send the data from the MCU to hyperterminal as it is.

  • RS232 is only 7 or 8 bits word so you need to send 0x04, wait (or check) TXBUF is empty then send 0xD1, wait (or check) TXBUF is empty then next data ...

  • bhanu pratap said:
    TXBUF1=0x04D1;

    This won't work. TXBUF is a byte register, the high-byte 8the uppe r8 bits9 would be swallowed (perhaps with a compiler warning of losing significant bits by implicit type conversion).

    As already suggested, you'll have to split the data into two bytes yourself. However, keep in mind that HyperTerm is a terminal program. It will try to interpret each byte separately as an ASCII code. So you won't see anything readable (even though you can capture it to file and then view with a hex viewer).

    MatLab, however, can of course take the two bytes and put them together into a word value again.

  • Sir

    you guys have been great help till now.

    But now I am facing one more bug that is 

    when I send TXBUF1='0';

    then through serial port the MATLAB gets the value as 6 

    and ehn I send TXBUF='1'

    then it gets the values as 103.

    Its not even its ASCII value where is the problem.

**Attention** This is a public forum