![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
Elysion
Joined: 03 Aug 2010 Posts: 26
|
Sending string value via RS232 |
Posted: Sat Aug 07, 2010 7:54 am |
|
|
,,,
Last edited by Elysion on Tue Aug 10, 2010 4:19 am; edited 2 times in total |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19385
|
|
Posted: Sat Aug 07, 2010 9:01 am |
|
|
The result you want to see at the target end, "111213", is _six_ characters long, not three. Also a 'string', needs a null terminator (zero character).
So your transmission end, needs:
Code: |
char s[7];
s[0]='1';
s[1]='1';
s[2]='1';
s[3]='2';
s[4]='1';
s[5]='3';
s[6]=0;
//Or:
char s[7]="111213"; //Combine declaration and initialisation
....
while(1)
{
fputs(s);
delay_ms(100);
}
|
Your reception end, also needs 7 characters minimum to hold this string.
Currently you are potentially sending the three ASCII characters 11, 12, and 13, which correspond to the commands 'VT' (vertical tab), 'FF' (Form feed) - will normally clear the screen), and 'CR' (carriage return), followed potentially by a whole sequence of garbage (whatever is in memory on the master system, untill a '0' is found), and overwritting the variables after your string on the slave system, with the same garbage....
Do a search on 'ASCII codes'. The UART sends numeric values. To send text, you need these values to be the correct ASCII codes for each character in turn. '1' for example, is actually sent as the code 49 (or 0x31). Using the single inverted commas in the declaration tells the compiler to put the correct ASCII code into the location, while using the double inverted comma, tells it to generate the sequence of required bytes, and _add_ the string terminator at the end.
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
Elysion
Joined: 03 Aug 2010 Posts: 26
|
|
Posted: Mon Aug 09, 2010 10:53 am |
|
|
...
Last edited by Elysion on Tue Aug 10, 2010 4:19 am; edited 2 times in total |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Aug 09, 2010 11:25 am |
|
|
You need to study programming and the C language. You need to
understand the difference between an integer and a char. You need to
understand what a string is. You need to read a C tutorial and
experiment with simple programs before you try to write your program.
Currently, you have an integer array, but you're using a string function
to transmit it. The fputs() function does not make an integer
array into a string.
You need to read an online C tutorial. Don't depend upon this forum
to teach you the C language. We really don't want to teach low-level C.
We'd like you to learn it outside the forum. Just being very honest here,
probably no one else will. |
|
![](templates/subSilver/images/spacer.gif) |
Elysion
Joined: 03 Aug 2010 Posts: 26
|
|
Posted: Tue Aug 10, 2010 4:18 am |
|
|
Thank you for your help.... |
|
![](templates/subSilver/images/spacer.gif) |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|