CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Sending string value via RS232

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Elysion



Joined: 03 Aug 2010
Posts: 26

View user's profile Send private message

Sending string value via RS232
PostPosted: Sat Aug 07, 2010 7:54 am     Reply with quote

,,,

Last edited by Elysion on Tue Aug 10, 2010 4:19 am; edited 2 times in total
Ttelmah



Joined: 11 Mar 2010
Posts: 19538

View user's profile Send private message

PostPosted: Sat Aug 07, 2010 9:01 am     Reply with quote

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
Elysion



Joined: 03 Aug 2010
Posts: 26

View user's profile Send private message

PostPosted: Mon Aug 09, 2010 10:53 am     Reply with quote

...

Last edited by Elysion on Tue Aug 10, 2010 4:19 am; edited 2 times in total
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Aug 09, 2010 11:25 am     Reply with quote

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.
Elysion



Joined: 03 Aug 2010
Posts: 26

View user's profile Send private message

PostPosted: Tue Aug 10, 2010 4:18 am     Reply with quote

Thank you for your help....
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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