EmbeddedRelated.com
Forums

Send A/D results to rs232 through uart

Started by Eugene August 14, 2009
Hello,
I apologize if this question was answered already, I could not find the answer. Perhaps someone can point me to it.

I'm using 430F5438 with FTDI's UART > RS232 converter (FT232R). I connect to it using PuTTY client.

I do A/D and send it to RS232 through UART:
UCA2TXBUF = (char)ADC12MEM0;

and instead of a number I see an ASCII character.

My question is how to send a number instead of the character or character representation of the number. Do I simply need a different terminal client that does not use ASCII encoding?

In any case, thank you very much in advance.

Beginning Microcontrollers with the MSP430

----- Original Message -----
From: "Eugene"
To:
Sent: Friday, August 14, 2009 6:28 PM
Subject: [msp430] Send A/D results to rs232 through uart
> Hello,
> I apologize if this question was answered already, I could not find the
> answer. Perhaps someone can point me to it.
>
> I'm using 430F5438 with FTDI's UART > RS232 converter (FT232R). I connect
> to it using PuTTY client.
>
> I do A/D and send it to RS232 through UART:
> UCA2TXBUF = (char)ADC12MEM0;
>
> and instead of a number I see an ASCII character.
>
> My question is how to send a number instead of the character or character
> representation of the number. Do I simply need a different terminal client
> that does not use ASCII encoding?

RealTerm will accept binary input, and can display it in various formats.
Alternatively, transmit the data as ASCII hex.

Leon

Eugene,
You are sending one byte character the contanis the 8 least significant bits of the ADC reading.
The your client is showing what it can represent with the byte value it has received. Most of the
values are in the ASCII visible range. For instance, if it receives 0x0A the TTY client would skip
one line instead of showing the byte ordinal value (10 in this case).
So, you have two choices: one is to make a program in your client to show the value and not the
character, or make your MSP's program to send all necessary ASCII characters to show the value. In
the example above the MSP should send at least two ASCII characters, 1 and 0 (0x31 and 0x30).
Further, since the ADC is 12 bit wide you are loosing the upper 4 bits when you give type CHAR to
read the ADC result.
(to be honest, since I am not a regular C programmer I don't know if the compiler already adjusts
the result to fit in 8 bits - using 4 bit right shift - or if it just chop the upper four).
-Augusto

On Sex 14/08/09 14:28 , "Eugene" c...@pcmansf.com sent:
> Hello,
> I apologize if this question was answered already, I could not find
> the answer. Perhaps someone can point me to it.
> I'm using 430F5438 with FTDI's UART > RS232 converter (FT232R). I
> connect to it using PuTTY client.
> I do A/D and send it to RS232 through UART:
> UCA2TXBUF = (char)ADC12MEM0;
> and instead of a number I see an ASCII character.
> My question is how to send a number instead of the character or
> character representation of the number. Do I simply need a different
> terminal client that does not use ASCII encoding?
> In any case, thank you very much in advance.
>
>

What do you mean by "see"?

Do you "see" the letter "W" at the very beginning of this reply?
Actually, the first thing you received is the binary pattern 01010111, which is the same as hex 0x57 or decimal 87. Which is also the ASCII for the letter "W".

In order for you to "see" decimal number 87, I should have send you the decimal numbers 56 55 which are the ASCII for "8" and "7".

--- In m..., "Eugene" wrote:
>
> Hello,
> I apologize if this question was answered already, I could not find the answer. Perhaps someone can point me to it.
>
> I'm using 430F5438 with FTDI's UART > RS232 converter (FT232R). I connect to it using PuTTY client.
>
> I do A/D and send it to RS232 through UART:
> UCA2TXBUF = (char)ADC12MEM0;
>
> and instead of a number I see an ASCII character.
>
> My question is how to send a number instead of the character or character representation of the number. Do I simply need a different terminal client that does not use ASCII encoding?
>
> In any case, thank you very much in advance.
>
Thank you for your reply. I guess my question is what is the easiest way to convert hex number to its ASCII representation. Is there a library available somewhere?

thank you

--- In m..., "old_cow_yellow" wrote:
>
> What do you mean by "see"?
>
> Do you "see" the letter "W" at the very beginning of this reply?
> Actually, the first thing you received is the binary pattern 01010111, which is the same as hex 0x57 or decimal 87. Which is also the ASCII for the letter "W".
>
> In order for you to "see" decimal number 87, I should have send you the decimal numbers 56 55 which are the ASCII for "8" and "7".
>
> --- In m..., "Eugene" wrote:
> >
> > Hello,
> > I apologize if this question was answered already, I could not find the answer. Perhaps someone can point me to it.
> >
> > I'm using 430F5438 with FTDI's UART > RS232 converter (FT232R). I connect to it using PuTTY client.
> >
> > I do A/D and send it to RS232 through UART:
> > UCA2TXBUF = (char)ADC12MEM0;
> >
> > and instead of a number I see an ASCII character.
> >
> > My question is how to send a number instead of the character or character representation of the number. Do I simply need a different terminal client that does not use ASCII encoding?
> >
> > In any case, thank you very much in advance.
>

On Fri, Aug 14, 2009 at 5:50 PM, Eugene wrote:

> Thank you for your reply. I guess my question is what is the easiest way to
> convert hex number to its ASCII representation. Is there a library available
> somewhere?
You could use sprintf. I believe it is part of stdio.

(* jcl *)

--

You can't create open hardware with closed EDA tools.

http://www.luciani.org


You could also DIY. For each hex digit, call:

unsigned char hex2ascii (char hexdigit)
{
if (hexdigit<=0x09) return ('0'+hexdigit);
else if (hexdigit<=0x0F) return ('A'+hexdigit-10);
else return ('?');
}

--- In m..., John Luciani wrote:
>
> On Fri, Aug 14, 2009 at 5:50 PM, Eugene wrote:
>
> > Thank you for your reply. I guess my question is what is the easiest way to
> > convert hex number to its ASCII representation. Is there a library available
> > somewhere?
> You could use sprintf. I believe it is part of stdio.
>
> (* jcl *)
>
> --
>
> You can't create open hardware with closed EDA tools.
>
> http://www.luciani.org
>
>
One easy way, if you can spare the overhead, is to use printf() and substitute putchar (which is called by prinft to write each character) with a function to send the char throught uart.

#include
void main (void)
{
int analogvalue
...
printf ( "%i",analogvalue);
...
}

int putchar(int u)
{
while(Buffer_Full)
; //wait until buffer empty
UARTBUFFER = (char) u;
return 1;
}

Regards,
Michael K.

--- In m..., John Luciani wrote:
>
> On Fri, Aug 14, 2009 at 5:50 PM, Eugene wrote:
>
> > Thank you for your reply. I guess my question is what is the easiest way to
> > convert hex number to its ASCII representation. Is there a library available
> > somewhere?
> You could use sprintf. I believe it is part of stdio.
>
> (* jcl *)
>
> --
>
> You can't create open hardware with closed EDA tools.
>
> http://www.luciani.org
>
>