Reply by Amin September 15, 20102010-09-15
Hi
problem not in your code ,you must understand different between characters in
bin, ASCII, hex and decimal.
your display just show your data in ASCII, then if you can't change display
format so change your data.
for example if you want send
num 1(dec) to display you must send 0x31(hex),
character A to display you must send 0x41(hex),
character a to display you must send 0x61(hex)
so just lock at below table:

http://www.cs.utk.edu/~pham/ascii.html

Amin


________________________________
From: hasan mustafa
To: c...
Sent: Mon, September 13, 2010 12:21:57 PM
Subject: [c28x] string to hex/string problem


hello everyone,

im facing a problem, im sending a HEX values to the PC, put the PC program
display it as string, BUT i want it as HEX, i cant change the PC part, because
its displaying other information too, it will be easier for me if i change the
TI code,
for example,
i want to send 0xEA on the screen i received it as ê,,, i want to see it as EA
i did like that
tempTXFrame= 0xEA;
ltoa(tempTXFrame,TCPTemp);

TXFrame[0] = 0x41;
TXFrame[1] = TCPTemp[0];
TXFrame[2] = TCPTemp[1];
////////////////////////
it suppose i receive 6561 but i receive on the screen 23 ?????? i think im using
the wrong function, im newbie with strings
any advice will be great, thanks all
Hasan




You can post a message or access and search the archives of this group on DSPRelated.com:
http://www.dsprelated.com/groups/c28x/1.php

_____________________________________
Note: If you do a simple "reply" with your email client, only the author of this message will receive your answer. You need to do a "reply all" if you want your answer to be distributed to the entire group.

_____________________________________
About this discussion group:

Archives: http://www.dsprelated.com/groups/c28x/1.php

To Post: Send an email to c...

Other DSP Related Groups: http://www.dsprelated.com/groups.php
Reply by "Prashant D. Kharade" September 15, 20102010-09-15
Hi Hasan,

I do not have experience on DSP. I am using AVRs.

Check below my one of the functions which sends combinations of Ascii & hex to serial port.

I am sending positive acknowledgement to a query from a PLC.

Buf[i] has 3 ascii characters, SOT (Start of text) Sequence (0x01), add (Address- 'A' to 'Z')

Then the hex byte 0x07. Please note this can be any hex value, as per length of the answer string.

Then the CRC. This is also Hex byte, return from a function.

Now again ascii byte 0x04 (EOT-End of string)

This is collected in a buffer ans-buf & send to serial port.

void pos_ack()

{ char ans_buf[8];

uint8_t i;

for(i=0;i<3;i++)

ans_buf[i] = buf[i]; //SOT, seq, add byte

ans_buf[3] = 0x07; //Length byte

ans_buf[4] = 0x06; // pos ack byte

ans_buf[5] = calculate_recd_CRC(ans_buf,5);

ans_buf[6] = 0x04; // EOT byte

ans_buf[7] = '\0';

uart1_puts(ans_buf);

}

Use free demo version of 'Docklight' available on net for checking the response on PC.

You can check hex & ascii values at same time.

All the best.

Prashant D. Kharade

Pune. India

From: c... [mailto:c...] On Behalf Of hasan mustafa
Sent: 13 September 2010 13:22
To: c...
Subject: [c28x] string to hex/string problem

hello everyone,

im facing a problem, im sending a HEX values to the PC, put the PC program display it as string, BUT i want it as HEX, i cant change the PC part, because its displaying other information too, it will be easier for me if i change the TI code,

for example,

i want to send 0xEA on the screen i received it as ,, i want to see it as EA

i did like that

tempTXFrame= 0xEA;
ltoa(tempTXFrame,TCPTemp);

TXFrame[0] = 0x41;
TXFrame[1] = TCPTemp[0];
TXFrame[2] = TCPTemp[1];

////////////////////////

it suppose i receive 6561 but i receive on the screen 23 ?????? i think im using the wrong function, im newbie with strings

any advice will be great, thanks all

Hasan

Internal Virus Database is out of date.
Checked by AVG - www.avg.com
Version: 9.0.819 / Virus Database: 271.1.1/2842 - Release Date: 04/29/10 11:57:00
Reply by Andrew Nesterov September 15, 20102010-09-15
> Subject: string to hex/string problem
> Posted by: hasanabouali198
> Date: Tue Sep 14, 2010 5:33 am ((PDT))

Hasan,

You would easily find the definitions of these conversion functions
(ltoa, atol and the like) on the net.

The conversion in itself is quite simple. The hex digits are '0' through '9'
along with 'A' through 'F'. Then, '0' is 0x30, 'A' is 0x41, 'x' is 0x78.

For exactly one byte number its symbolic representation is "0xHH", or 4 byte
array of char:

char str[5] = {0x30, 0x78, 0x00, 0x00, 0x00}; // terminating zero in [4]
unsigned char num;

num = ....; // assign a value to num

// MS hex digit
if (((num >> 4) & 0x0F) < 0x0A)
str[2] = ((num >> 4) & 0x0F) + 0x30;
else
str[2] = ((num >> 4) & 0x0F) + 0x41;

// LS hex digit
if ((num & 0x0F) < 0x0A)
str[3] = (num & 0x0F) + 0x30;
else
str[3] = (num & 0x0F) + 0x41;

This procedure should be easily expanded to convert 2 byte or larger numbers.

HTH,

Andrew

> hello everyone,
>
> im facing a problem, im sending a HEX values to the PC, put the PC program
> display it as string, BUT i want it as HEX, i cant change the PC part,
> because its displaying other information too, it will be easier for me if i
> change the TI code,
>
> for example,
>
> i want to send 0xEA on the screen i received it as ,, i want to see it as
> EA
>
> i did like that
>
> tempTXFrame= 0xEA;
> ltoa(tempTXFrame,TCPTemp);
>
> TXFrame[0] = 0x41;
> TXFrame[1] = TCPTemp[0];
> TXFrame[2] = TCPTemp[1];
>
> ////////////////////////
>
> it suppose i receive 6561 but i receive on the screen 23 ?????? i think im
> using the wrong function, im newbie with strings
>
> any advice will be great, thanks all
>
> Hasan
>



You can post a message or access and search the archives of this group on DSPRelated.com:
http://www.dsprelated.com/groups/c28x/1.php

_____________________________________
Note: If you do a simple "reply" with your email client, only the author of this message will receive your answer. You need to do a "reply all" if you want your answer to be distributed to the entire group.

_____________________________________
About this discussion group:

Archives: http://www.dsprelated.com/groups/c28x/1.php

To Post: Send an email to c...

Other DSP Related Groups: http://www.dsprelated.com/groups.php
Reply by hasan mustafa September 14, 20102010-09-14
hello everyone,

im facing a problem, im sending a HEX values to the PC, put the PC program
display it as string, BUT i want it as HEX, i cant change the PC part,
because its displaying other information too, it will be easier for me if i
change the TI code,

for example,

i want to send 0xEA on the screen i received it as ,, i want to see it as
EA

i did like that

tempTXFrame= 0xEA;
ltoa(tempTXFrame,TCPTemp);

TXFrame[0] = 0x41;
TXFrame[1] = TCPTemp[0];
TXFrame[2] = TCPTemp[1];

////////////////////////

it suppose i receive 6561 but i receive on the screen 23 ?????? i think im
using the wrong function, im newbie with strings

any advice will be great, thanks all

Hasan